Posts Tagged: JUnit

No side effects in test code

When a TestCase runs, it should either succeed or fail: there should be no side effects. For example, Testcases should not write to the console or to a log file, or save anything to a database. There are two reasons for this. Continue reading “No side effects in test code” →

Write useful JUnit test suites

Structure your JUnit test suites to simplify unit testing — you can easily run all your tests with one command.

In every package directory, create a test suite called AllTests, containing all TestCases in that directory. For example: com.zikzak.widget.util.AllTests (This can be generated automatically by the Eclipse IDE.) Continue reading “Write useful JUnit test suites” →

Don’t write useless Junit tests

This may seem obvious, but many JUnit tests are written that don’t really test anything useful.

Don’t write tests cases for code that’s too simple to fail on its own: that would be a waste of time. You’re supposed to write tests that test your application code, not the test framework or the compiler.