I'd separate concerns and unit test the parser individually. object wiring and execution path verification would be a system test (integration test) with the real non mocked Main class .. of course it therefor had to return an outcome in some way.
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to a topic in the Google Groups "Clean Code Discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clean-code-discussion/vvca9BGHwes/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
On Sun, Jan 19, 2014 at 10:57 AM, Andreas Schaefer <schaeferi...@gmail.com> wrote:
I'd say more important than 100% (unit) test coverage is the developers confidence in the codebase and that the system works. some things just don't need to be under test in a harmonic, good dev team.
I know that doesn't solve the academics of your problem, but you could have a system test using a true mock of Solver that verifies the outcome on the lowest level .. this way avoiding the need to parse ASCII or whatever the eventual output format would be.
But what do you mean with true mock of Solver?
But what do you mean with true mock of Solver? Solver is an object created by Main, so how can it be mocked out in a system test? The two boundaries of this program are the main method (for passing the user input via the args[]) and its the standard output, so that the user can view the result of the execution
And since Main is also part of the codebase, it should be tested too IMHO, preferrably with a unit test
And since Main is also part of the codebase, it should be tested too IMHO, preferrably with a unit testFor being unit tested it (an the component it depends on as well) had to be designed in such a way that you can "mock out" all of it's dependencies so that it can be tested in complete isolation. If it's not completely isolated, then it's not a unit test anymore but some kind of integration test.
Paolo Laurenti Software Developer
lauren...@gmail.com | http://paololaurenti.wordpress.com
@Andreas: I interpreted Unit Test like you do but during the last weeks I changed my mind. I saw the talk of Ian Cooper "TDD, where did all go wrong" and after that I started to read "Test Driven Development Explained" by Kent Beck.
Ian Cooper said that Kent Beck was misunderstood when he introduced TDD: the word "Unit" is not related to the SUT but to the test. Unit tests should verify a single behavior in isolation from others test (i.e: a unit test shouldn't use a DB because a test execution that modifies some data, could interfere with the execution of other tests that use the same data. Yes, you could rebuild every time the DB but this is a trick, not the solution of the problem).Therefore you can test many classes with one single test. These classes should collaborate at runtime with their objects, in order to implement the behavior that the system should provide.Thinking that "Unit" is referred to the SUT makes the tests coupled to implementations details (you need to mock/stub/fake/etc every dependencies that your SUTs need), and every time you will change a system behavior, several tests will be red with no reason...
@Rusi: Sorry, I haven't an idea about how to unit test your Main. I think that its responsibilities should be only objects creations/wiring. These responsibilities have to deal with a lot of implementation details (you have to instantiate the concrete objects that you high level policy objects depend on) so I think that Main and all the "Declarative Layer" should be tested by some (a few) system tests and not by Unit test ...
... (they focus only on behaviors).
@Palo, I think Ian Cooper means component tests in his talk. He shifts the granularity of the term "unit" from class to component. So if a component consists of 20 collaborating classes, Ian suggests not testing the classes in the component individually, but testing the component's behaviors. These tests would use only the component's API, and see the component as a black box. I think such component tests are not better or worse than unit tests, they are just different. The tests are less coupled to the implementation and they test multiple collaborating classes with one shot.
But on the other hand, the tests can't put strong focus on the individual class, making it harder to test edge and error cases if the only entry point they use is the component's Facade.
@Andreas, thank you for the suggestions and references. Yet I am still curious how the main part of the application can be 100% unit-tested, taking into account that there is a main() method involved. Currently, I don't see a good way to deploy test doubles in the main part, if only using conventional injection technques or subclassing and overriding. Maybe you could post a code example?
you extract the wiring away from Main (as already suggested), wire the SolverMock up in there and thus could use the production Main class
But on the other hand, the tests can't put strong focus on the individual class, making it harder to test edge and error cases if the only entry point they use is the component's Facade.From my experience I found that the majority of problems I faced with TDD, are tests with a "strong focus on individual class".
When I wrote these kind of tests I found myself in trouble when I have to change the behaviors of the system that they implement. One key concept of the speech of Ian Cooper is that you can write test coupled to implementation details in order to explore an a solution of a problem. The difference is that when the exploration is finished and you are good with your solution, it would be a good idea to delete these tests. I know it's difficult to accept to delete some tests we wrote, but, in my opinion, tests that are coupled to implementation details, after the exploratory phase where they were useful, can only create problems.