language agnostic - Unit Testing: Logging and Dependency Injection -
So logging on the Internet from SO and other sites is the best answer:
Zero DoSomething () {Logger.Log ("Do something!"); // code ...}
Now you generally avoid static methods, but in the case of logging (a special case) this is the easiest and obvious way. Inside the stable class, you can easily inject an example through a config file / framework to give the same effect as the DI.
My problem comes from a unit test perspective.
On the example above, assuming the point of DoSomething () was to add two numbers simultaneously, I will write my unit tests for this right about what is the logging about?
Will I write a unit test for logging (still use fake examples for logger)? I know that if this was the case then I would have to write an integration test to make sure that the logger was actually written in a log file, but I'm not sure.
The following test driven development (which I do) unit any advice? Personally, I practice TDD / BDD in a very religious way and almost never enter.
does not. With some exception logging, either a developer is a factor of convenience or applicability, it is not part of the main specification of the method. This method tend to change a much higher rate than the actual meaning of the method, so you add some more informative logging , So you turn off breaking tests.
This is probably something to test, use the logging subsystem, but for most apps I do not test that each class uses logs in a particular way.
Comments
Post a Comment