The Art of Unit Testing
The Art of Unit Testing
Integration Tests
Integration tests differ from unit tests:
May not execute quickly
May not use static test values and therefore execute
differently every time they are run
May use one or more real dependencies
e.g. System time, file system, production/test database
Organization:
Should be separated from unit tests to achieve a feeling of
safe green zone (discussed later in book)
Traditional Development vs
Test-Driven Development
Traditional Development
Test-First Development
2.Make the test pass by writing production code that meets the
expectations of your test. The production code should be kept as
simple as possible.
3.When the test passes, youre free to move on to the next unit test or
to refactor your code to make it more readable, to remove code
duplication, and so on.
Refactorting
Refactoring means changing a piece of code without
changing its functionality. If youve ever renamed a
method, youve done refactoring. If youve ever split a
large method into multiple smaller method calls, youve
refactored your code. The code still does the same thing,
but it becomes easier to maintain, read, debug, and
change.
Refactoring can be done after writing several tests or after
writing each test. Its an important practice, because it
ensures your code gets easier to read and maintain, while
still passing all of the previously written tests.
Suggested Reading:
.(1) This book
.(2) Test-Driven Development: by Example by Kent Beck (Addison-Wesley
Professional, 2002)
.(3) Growing Object-Oriented Software, Guided by Tests by Steve
Freeman & Nat Pryce (Addison-Wesley Professional, 2009)
.(3) Clean Code by Robert C. Martin (Prentice Hall, 2008)