28
Test Driven Development Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ More JUnit Tests for the DVD app

Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Test Driven Development

Produced

by:

Mairead MeagherDr. Siobhán Drohan

Department of Computing and Mathematicshttp://www.wit.ie/

More JUnit Tests for the DVD app

Page 2: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Topic List

• DVD and DVDTest.java

• JUnit Testing of Library.java (which includes testing of XML reading/writing)

• Testing Driver.java

Page 3: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

public class DVD

{

private String title;

public DVD(String title){

setTitle(title);

}

public void setTitle(String title) {

if (title.length() <= 20){

this.title = title;

}

else{

this.title = title.substring(0,20);

}

}

public String getTitle() {

return title;

}

public String toString() {

return "DVD Title is: " + title;

}

}

DVD.java

Page 4: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 5: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 6: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 7: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 8: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 9: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

DVDTest.java

Page 10: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Topic List

• DVD and DVDTest.java

• JUnit Testing of Library.java (which includes testing of XML reading/writing)

• Testing Driver.java

Page 11: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Create a new JUnit Test Case within the “test” folder

Call the test class, LibraryTest

Generate the default setUp() and tearDown() methods.

Page 12: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Generated LibraryTest.java

Page 13: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java

We need to write at least

one test for each of these

methods.

Page 14: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing the constructor

To test the constructor, we will create a Library object. Then we will call the getDVDs() method and ensure that the returned ArrayList has a size of 0.

Page 15: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing the constructor

Page 16: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing add(DVD)

Page 17: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java
Page 18: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing getDVDs and setDVDs

Page 19: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java
Page 20: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing listDVDs()

Page 21: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java
Page 22: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing save and load

Page 23: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing save and load

Page 24: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Library.java – testing save and load

Page 25: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Topic List

• DVD and DVDTest.java

• JUnit Testing of Library.java (which includes testing of XML reading/writing)

• Testing Driver.java

Page 26: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Driver.java

• JUnit is not used to test the class that takes input from the console.

• Why do you think this is?

Page 27: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java
Page 28: Test Driven Development - GitHub Pages · Topic List •DVD and DVDTest.java •JUnit Testing of Library.java (which includes testing of XML reading/writing) •Testing Driver.java

Department of Computing and Mathematicshttp://www.wit.ie/