0

The following point (in bold) is mentioned in this famous Stackoverflow question: Unit Tests allows you to make big changes to code quickly. You know it works now because you've run the tests, when you make the changes you need to make, you need to get the tests working again. This saves hours.

In my case, I finished writing a program in Python 2.7. Now I started writing the test using PyUnit. The test will be another class (derived from "unittest.TestCase") which will exist in a different file. (I did not know that the test should be written before or during development at the beginning)

As I am writing the test, I started wondering: In case I modified my program code, and ran my test again, then the test should still work without changes because it was not changed (the above point suggests that you need to make changes to test to make it work!) It is the program code itself that was changed and not the test.

I do not understand how the last sentence in the above-mentioned point makes sense. I hope I can find somebody who can help me in understanding it.

Thanks

Community
  • 1
  • 1
Ababneh A
  • 1,104
  • 4
  • 15
  • 32
  • "_In my case, I finished writing a program in Python 2.7. Now I started writing the test using PyUnit._" As you imply in your parenthetical comment, that was your first mistake. If you're serious about unit testing, you should consider Test Driven Development, where you begin by writing a failing test that should pass, then write the code to make it pass, then add a failing test that should pass, then ... _ad infinitum_. – Ross Patterson Oct 20 '13 at 21:12

3 Answers3

1

Unit tests verify contracts. They won't change if contracts are unchanged. A programmer can freely modify implementation feeling himself protected from errors by UT.

The sentence you quote is about changing contracts - UT indicates a change in contract and programmer should ensure this change is reasonable. In well designed software this is easier than verifying correctness of implementation, hence speed-up of the process.

Basilevs
  • 22,440
  • 15
  • 57
  • 102
0

The test should actually execute the package code, so that breaking the package will show up in tests.

Thomas Orozco
  • 53,284
  • 11
  • 113
  • 116
0

I think the highlighted sentence should have little more details, like if the original 'contract', or 'requirement' of the module its testing is changed, or not changed. My quick read says, the original contract has not changed. But still you have to run, and make sure it works. Or if your code improved performance due to your modification, it should readjust the test to reflect improvements. But again requirement remained same, and your code is performing better.

tips
  • 21
  • 3