Comments on: Unit Testing and Automated Blackbox Testing https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/ Fri, 12 Jan 2018 17:18:04 +0000 hourly 1 https://wordpress.org/?v=7.0 By: Unit Testing Without Mocks - Simple Programmer https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-548 Thu, 11 Jan 2018 22:53:39 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-548 […] my last post, I revealed my conclusions regarding what to do instead of misusing IoC containers and interfaces […]

]]>
By: Matt https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-547 Mon, 14 Feb 2011 22:22:10 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-547 I’ve found that writing interfaces and doing inversion of control just for the sake of unit testing makes the underlying code harder to understand and troubleshoot. I completely agree that these interfaces should only be used when the software design may need to support multiple implementations all from production code. The black box automated tests that verify a requirement or usage scenario are great for restoring the confidence lost from not unit testing those classes with external dependencies. However, those tests also take a lot longer to run and may be limited to only running nightly. Commercial tools, like http://tinyurl.com/4dofj4p, can automatically generate the missing unit tests with mocks for external dependencies. These synthetic tests do not instill the same confidence as a QA test script for a specific requirement. Those BAT are still valuable. Instead, automatically generated tests are useful for quick regression testing. When a class calls external methods in a certain order and then those calls change, the automatic unit tests will detect it. These tests require more maintenance work during changes from code development, but that work is mitigated by automated test generation.

]]>
By: Clement https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-546 Wed, 19 Jan 2011 04:27:18 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-546 Awesome article, I’m with you a 100%.
The title of this serie is spot on. Once the dev community have played enough with their new toys (DI, unit testing), it’s time to go back to what really works.

]]>
By: Loose Couplings https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-545 Tue, 18 Jan 2011 14:44:11 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-545 Good post and good series. While I don’t agree with every point you make, it’s a good read.

I find your Level 1-Level 4 class categorization interesting but not really useful for the purposes of testability. I tend to mentally categorize in terms of newables and injectables (and then sub-categorize in DDD terms). I tried to explain this categorization in this post http://loosecouplings.blogspot.com/2011/01/how-to-write-testable-code-overview.html

I also find the practice of ‘using IoC containers all over your app’ alarming. I touched on a similar point [trying to preach the virtues of manual DI] in http://loosecouplings.blogspot.com/2011/01/dependency-injection-using-di-container.html

I think we (and others discussing similar issues in the blogosphere now) are all working toward the same goal here from different angles. If you figure it out, let me know! 🙂

]]>
By: John https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-544 Mon, 17 Jan 2011 14:34:20 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-544 In reply to jsonmez.

Thanks for reply.

In my opinion unit tests is one of the tangible assets that good quality code has. Other ones such as easy maintenance, easy to read code and so on are too hypothetical for management to convince them that writing high quality code is important. By using BAT tests it is more difficult to get someone believe that code quality matters.

]]>
By: jsonmez https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-543 Mon, 17 Jan 2011 14:25:06 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-543 In reply to John.

As for the slowness of BAT tests, there are many solutions available today that weren’t as readily available before that can make running BAT tests in parallel reduce to total time by a great deal. Obviously you wouldn’t be able to run these kinds of tests as quickly as traditional unit tests, but running them on a daily or even 2x a day schedule will provide an huge benefit.

As for someone new to TDD. I would suggest avoiding mocks and DI containers, but I would not suggest at all avoiding unit tests or TDD in general. In my next post in this series I planned to talk about how to refactor code in a such a way that a large portion of the code requires level 1 or level 2 unit tests. Using a TDD approach without allowing yourself mocks or DI naturally leads to this kind of code.

I agree that some teams may write BAT tests instead of caring about OOP and other best practices, but those teams are likely to have been teams that weren’t writing unit tests or any quality either. In the long run, if you have a complete end to end regression suite that you can run daily though, (as much as it pains me as a software craftsman to say this), some of the principles we hold dear are not nearly as important, since failures in functionality are found so quickly.

]]>
By: John https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-542 Mon, 17 Jan 2011 13:00:13 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-542 What about the fact that BAT tests are usually slower compared to other tests? Usually they have to launch browser (e.g. Watin) and the system needs to connect to some kind of database making the whole process slower.

Another question: what would be your advice to someone new to TDD? Should they avoid mocks and DI containers? It’s very easy to use Watin even if you have very bad quality code which is difficult to test. Advocating usage of BAT tests might cause teams not caring about OOP and other best practices.

]]>
By: jsonmez https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-541 Sat, 15 Jan 2011 08:21:51 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-541 In reply to Martin Rue.

Thanks for the comment. Sorry for the late reply. I believe you get exactly what I am saying. Glad to hear that someone else has come to some of the same conclusions.

Your calculator example is spot on. That is exactly why I don’t like mocks anymore. Very good point.

]]>
By: ntcoding https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-540 Fri, 14 Jan 2011 23:05:35 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-540 I think you and Jimmy Boggard should start showing us a few examples. The theory is sound, but then you could say that about the jurassic park movie 🙂

Come one John – examples P-lease.

]]>
By: Martin Rue https://simpleprogrammer.com/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-539 Fri, 14 Jan 2011 19:21:12 +0000 https://simpleprogrammer.com/2011/01/14/back-to-basics-unit-testing-automated-blackbox-testing-and-conclusions/#comment-539 My thinking on this fits pretty much exactly with yours. I’m finding it more and more important to write really simple unit tests that are just assertions of some expected output state.

And as you’ve noted, I’ve also found that any moderate use of mocks, in the end, just couples the test to the implementation and certainly increases the friction of any future refactoring. I’m now avoiding those where I can completely.

The way I see it: If I go into my calculator class and completely change the way my internal add method works, so long as when 5 and 5 are input I get back 10, that’s all I care about. I certainly don’t want my new refactoring to break a test because my internal add method is no longer calling some other internal method that some mock had an expectation on just so the unit test could be “pure” and without dependencies.

Recently I’ve taken this same thinking (simple observations of state) to the BAT (to use your terminology here) level and started creating automated end-to-end tests that map pretty much directly to a feature. They are essentially my virtual customer who, multiple times per day, checks that every feature they have ever asked for still work in the way they expect. I think the most value comes from these tests.

Above everything else, I want to know that the software works in the way a user sitting in front it will expect. The only way to do that is to automate the sitting in front of it and checking.

Of course, the safety net argument still applies for unit tests and we need to be able to refactor code and have quick feedback about any broken behaviour (where a large set of constantly running BATs might not provide that quickly enough) – so a decent set of unit tests is still really important.

But focusing on the value that each and every unit test will give you is where I’m at now. To me, a unit test is more code – a form of debt, and I am going to evaluate the need for each one to make damn sure it’s paying for itself it terms of its reliability and usefulness. If it doesn’t negate its own debt, I don’t want it. I’m not going to test that my view has been passed the correct type of model any more.

Rant over. Great most and very thought provoking 🙂

]]>