Unit testing: questions for beginners

Finally, I start with unit testing, finding out that I have to do this for a while, but I have a few questions:

  • Should or should I not repeat parent classes when testing children if no methods were overwritten?
  • Conceptually, how do you test the submitted part of the form? I am using PHP. ( Change ). The reason I'm asking about this is because I have a high-level form class that generates the form, validates it, filters it and generates any error messages, taking a JSON-like array as input and Change : It looks how: Edit : this may be the answer.)
  • If you have an optional parameter in a method, you should write a test for both when they are present and when they are not?
  • Should unit testing in any way be combined with test code execution or should they remain completely separate?
  • Is there a good reason not to run your full test suite every time?
  • I just get my terminology right, what unit in unit testing? Class being testing? Method? Parameter? Something else?
+11
php unit-testing
Jan 23 '09 at 16:33
source share
4 answers
  • Check the parent, test child; if the child does not override the parent method, you do not need to retest it.
  • I'm not sure I understand the second. You can use Selenium to automate form testing. Is that what you mean?
  • Tests should include a โ€œhappy journeyโ€ and all extreme cases. If you have an optional parameter, write tests to show the correct operation with the value present and absent.
  • Unit tests, integration tests, acceptance tests, load tests are different ideas that may have some coincidence.
  • I bet there are good reasons, but if you make automatic builds that automatically run a test package, why don't you run them? It may come to mind for a long time, but this is the only reason I can think of. The value indicates that they all continue to go through, and that the changes you made did not break anything.
  • Unit test for me means the class you are testing, which may have several methods. I associate them with classes, not forms. Forms means UI and integration testing for me.
+8
Jan 23 '09 at 16:46
source share

(Not quite in the same order as your questions)

  • If the full test suite does not take too long, you should always run it. You often do not know what side effects may result from changes.

  • If you can combine speed tests with your favorite testing module, you should do it. This provides additional information about the quality of your changes. But do this only for critical parts of your code.

  • From Wikipedia: "Unit is the smallest verifiable part of the application."

+5
Jan 23 '09 at 16:46
source share

Answers to questions in order:

  • If parent classes are already tested, avoid duplication and just check out new aspects of the child or any aspects that the child has changed.
  • Not sure - done very little PHP.
  • Yes => check all aspects of the method.
  • You may have separate tests that test performance, but they will focus on performance, as others may focus on testing functionality. Do not mix both in the same test.
  • Ideally, you should run them every time and often. Sometimes, if the execution time is huge, you may want to reorganize them into smaller packages, and then only execute the completed suites when something changes, but still do it periodically.
+2
Jan 23 '09 at 16:46
source share

I will answer what I can.

Should I re-test parent classes when testing child elements if no method has been overwritten?

You should fully test the parent and then only check what changes are in it.

If you have an optional parameter in a method, you should write a test for both when they are present and when not?

Yes, check everything that causes a change in behavior.

Should unit testing in any way fit with test code runtime or should it remain completely separate?

They must remain separate. Unit testing is the verification that a method does what it should. You have to check the execution time of the code at the system level, and then break it to find bottlenecks. Testing the performance of each individual unit will lead to premature optimization.

Is there a good reason not to run the full test suite every time?

If your test suite is huge and time consuming, you can only run a subset of it while you are still developing. You should run the whole package when you (think you did) to make sure that you havenโ€™t broken anything.

Just because I understand my terminology correctly, what does a unit in unit testing refer to? Test class? Method? Parameter? Something else?

"Unit" refers to the test method. This is the smallest unit that makes sense to break software. A class method can use class B, but any test you write for this method should not worry. Just check this method.

+2
Jan 23 '09 at 16:57
source share



All Articles