Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing increasing features with unit tests

I'm wondering what the best practices are in Test Driven Development / testing using unit tests when it comes to increasing features.

E.g. I have a requirement when an object of Class Foo receives a bar() message, it should update a given field counter accordingly. I create a test case for this, which creates a Foo object and then tests the requirement.

Now what should I do if there is a new requirement, that when Foo receives a bar() message also another field, counter2 should be updated. Should I create a new test case for this, which checks only the second requirement, or do I just update the first test case?

like image 544
Alfonso Avatar asked Apr 08 '11 12:04

Alfonso


People also ask

What should you test with unit tests?

Unit tests should validate all of the details, the corner cases and boundary conditions, etc. Component, integration, UI, and functional tests should be used more sparingly, to validate the behavior of the APIs or application as a whole.

What is the difference between unit test and feature test?

Feature and Unit tests are methods of software testing that isolate a part of a system and test it. A unit test could look at something small like a single method e.g. adding a row to a database, whereas a feature test will have a broader view such as registering a user and validating their details.


2 Answers

Seems that your question contains the answer. From my practice, if it's a new requirement, which doesn't change previous one, then you should create a new test for it. If it's a change of requirements -- then you should modify old test, to fit these updated requirements, and do it prior to implementation.

like image 196
Illarion Kovalchuk Avatar answered Oct 14 '22 05:10

Illarion Kovalchuk


I would generally add a new test case, so that the two features are kept independent in testing, and which test fails indicates which feature is wrong.

like image 23
Don Roby Avatar answered Oct 14 '22 06:10

Don Roby