Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Log4net does not throw exceptions: <a href="http://logging.apache.org/log4net/release/faq.html" rel="noreferrer">http://logging.apache.org/log4net/release/faq.html</a></p> <p>Writing to an log on disk or in a database in a unit test is counterproductive; the whole point is automation. You shouldn't have to check the logs every time you run tests.</p> <p>If you truly need to verify that a call was made to log something, you should mock the <code>ILog</code> interface and assert that the appropriate method was called.</p> <p>If you are using a mocking framework, this is trivial. If you aren't, you can create a <code>TestLogger</code> class that implements or partially implements <code>ILog</code> and exposes extra properties that show how many times a given method was called. Your assertions will check that the methods were called as expected.</p> <p>Here is an example of a class to be tested:</p> <pre><code> public class MyComponent { private readonly ILog _log; public MyComponent(ILog log) { _log = log; } public string DoSomething(int arg) { _log.InfoFormat("Argument was [{0}]", arg); return arg.ToString(); } } </code></pre> <p>and the test (using Rhino.Mocks to mock the ILog):</p> <pre><code>[TestClass] public class MyComponentTests { [TestMethod] public void DoSomethingTest() { var logger = MockRepository.GenerateStub&lt;ILog&gt;(); var component = new MyComponent(logger); var result = component.DoSomething(8); Assert.AreEqual("8", result); logger.AssertWasCalled(l =&gt; l.InfoFormat(Arg&lt;string&gt;.Is.Anything, Arg&lt;int&gt;.Is.Equal(8))); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload