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?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With