Comments on: Back to Basics: Why Unit Testing is Hard https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/ Tue, 09 Jan 2018 22:24:34 +0000 hourly 1 https://wordpress.org/?v=7.0 By: jsonmez https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-496 Tue, 17 Mar 2015 00:00:00 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-496 In reply to Arne Mertz.

Great points. I have to say that I agree with you. Very pragmatic approach. Units don’t have to be classes.

]]>
By: Arne Mertz https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-495 Sun, 15 Mar 2015 14:52:00 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-495 In reply to jsonmez.

I disagree on that definition of a unit. I think it is important that those tests are called unit tests and not class tests. When a class can’t possibly work without a specific other class, is it still a unit? I guess the definition of the unit has to be done on a case-to-case basis.
Since unit tests are used in a certain way, they should have specific properties: they should run fast and should not depend on the platform or on I/O etc. That means they should not test too much code, iow, the code under test should a reasonably small portion. But not necessarily as small as possible, i.e. not a single class.
I know this is against the puristic and idealized view of theory, but it is a pragmatic view. If you know that the actual class you depend on does its job well (because you have it under unit tests) and don’t care about how often the dependent class actually calls which function of it, then there is no need to mock it away.
Imo the “units” we test should be small enough, but not smaller.

]]>
By: tibbbi https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-494 Sun, 15 Feb 2015 23:52:00 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-494 Ive read a lot about unit testing and even tested it, but I somehow still dont get the point of it. Why the hype about it when it can all be done with if/else?

]]>
By: jsonmez https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-493 Thu, 05 Dec 2013 16:07:00 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-493 In reply to Hariharan Mahadevan.

You are correct, a unit is something that we construct from the language, but doesn’t represent truly what a unit is logically in our code. The problem is that unit testing is based on a the language and the tools. We want to be able to test the smallest unit of code that is cohesive, which is usually a class.

]]>
By: Hariharan Mahadevan https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-492 Thu, 05 Dec 2013 11:48:00 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-492 Great article I was searching for.. But I have a even bigger doubt on how we think, all along the article, we have been discussing how to isolate calculator class and test. Here I have a question to define Unit (Software unit) itself. Why should one class be called an Unit, when it depends on few other classes to process the operands? The trend of layered architecture front end calling –> controller —>action —>service layer —>dao; my functional unit has spread to larger set of classes. Is testing one class still valid in these scenerios ? Single class may be atomic but not usable when it cannot deliver a unit of function upon execution. Your comments

]]>
By: Jason Young (@ytechie) https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-491 Wed, 03 Apr 2013 14:43:27 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-491 Great post. Honestly, I was pissed off when I read the title, but your analysis is sound. However, I still wholeheartedly believe that it is definitely worth it. Your code will be better designed. Your code will be easier to maintain. You will develop faster.

]]>
By: PK https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-490 Thu, 16 Dec 2010 03:06:14 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-490 In reply to PK.

Test code is as important as production code. It can have bugs. It needs to maintained. And we should strive to keep it as stable as possible.
Functional/Features tests document a large part of what you code is doing. By looking at these tests, one should be able to identify interaction and state changes going on in a particular scenario. I think the focus should be on improving the quality of the test code, rather than questioning the value of these tests.

]]>
By: PK https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-489 Wed, 15 Dec 2010 10:49:13 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-489 I have been following your back-to-basics series and will be waiting to see the solution. I think, there are two things going on here….there are unit tests (level1 and 2) and functional/feature tests (level 3 and 4). Functional/Feature tests are always hard to test and maintain. But, with appropriate naming and structuring you can ensure that they are easier to maintain. Without feature/functional tests bugs creep into your code in long term and doing changes to the code becomes a nightmare. It is very essential to have these tests to ensure stability of code. There is nothing wrong in mocking and I don’t see any reason why it should create complexity. Code written to test code is also after all code and it can be awesome/aweful.

]]>
By: Marcus https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-488 Tue, 14 Dec 2010 20:21:04 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-488 I was nodding so much my neck hurts. Friggin excellent, buddy. I’ll stay tuned.

]]>
By: Samuel Jack https://simpleprogrammer.com/back-to-basics-why-unit-testing-is-hard/#comment-487 Tue, 14 Dec 2010 10:03:19 +0000 https://simpleprogrammer.com/2010/12/12/back-to-basics-why-unit-testing-is-hard/#comment-487 In reply to Samuel Jack.

Sorry for the slip-up with your name: (Jason -> John) Guess that’s what comes of seeing jsonmez, and having some familiarity with Javascript!

]]>