TDD Test-Driven Development
JUnit 4.0 To use annotations need to import org.junit.Test To use assertion need to import org.junit.Assert.* No need to extend from junit.framework.TestCase No need to prefix test method with ‘test’ Test method is annotated Method annotated executes before every test. Method annotated executes after every annotations for one- time set up and tear down.
JUnit Annotations Checking for annotation can take a parameter, which declares the type of Exception that should be = Exception.class) public void nullPointerParameter() {… The test fails if no exception is thrown. Checking annotation can take a parameter, which declares period in = 10) public void nullPointerParameter() {… The test fails if it takes more than 10 milliseconds. Test annotation mean that test was ignored and not run.
What is TDD? Test-Driven Development (TDD) is a software development technique that involves repeatedly first writing a test case and then implementing only the code necessary to pass the test. Two basic rules: 1.Never write a single line of code unless you have a failing automated test. 2.Eliminate duplication.
What is TDD? Add a test Run the test Update the program Run the test Pass, Development continues Pass, Development stops Fail Pass
Why is TDD good? No unnecessary code. TDD helps to catch defects early in the development cycle. TDD-derived tests can also serve as a form of product documentation. TDD can drive the design of the program. TDD can lead to more modularized, flexible, and extensible code. i.e. to smaller, more focused classes, coherence, and cleaner interfaces TDD ensures that all written code is covered by a test. Problematic: reusable components, GUI, databases.