Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 TDD Test-Driven Development

2 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 with @Test. Method annotated with @Before executes before every test. Method annotated with @After executes after every test. @BeforeClass and @AfterClass annotations for one- time set up and tear down.

3 JUnit 4.0 - Annotations Checking for exceptions: @Test annotation can take a parameter, which declares the type of Exception that should be thrown. @Test(expected = Exception.class) public void nullPointerParameter() {… The test fails if no exception is thrown. Checking timeout: @Test annotation can take a parameter, which declares period in milliseconds. @Test(timeout = 10) public void nullPointerParameter() {… The test fails if it takes more than 10 milliseconds. Test ignorance: @Ignore annotation mean that test was ignored and not run.

4 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.

5 What is TDD? Add a test Run the test Update the program Run the test Pass, Development continues Pass, Development stops Fail Pass

6 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.


Download ppt "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."

Similar presentations


Ads by Google