Pergunta de entrevista da empresa DWS

What is unit testing? How do I go about writing a unit test? Do I focus a unit test on a class or a method? Would I write one or more tests per method? What are some unit testing frameworks?

Resposta da entrevista

Sigiloso

8 de out. de 2012

Unit testing is automated testing of individual smallest units of program code to see if they fulfill the contract they were written for correctly. (-> Design by contract). "Smallest units" of program code can be classes or methods. In .Net, the Visual Studio Unit Testing Framework generates default unit tests for the methods of a class. So, when you have coded the basic design of a class and its methods with their signatures (possibly from a UML class diagram), the tests can be auto-generated and then filled in. By default, there is one test per method; if different input-output relationships of the method have to be tested, this is usually done with different method calls within the one test. This may work differently with different unit testing frameworks: http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks In "pure" test-driven development, the test is written even before the class, and the class then written so that the test will compile (and later, when coding is finished, even run without an error).

1