On completion of this lab you should be able to:
Write JUnit Test Cases for the DVD app.
Run and interpret the results of JUnit test classes.
In this practical, you will create a test class for DVD.java.
Create a new project called DVDLibraryV3.1 in Eclipse.
Copy the following classes into the project:
Create a new folder called lib and copy the XStream jar file into it. Add this jar file to your build path:
In this section, you may need to refer to your lecture slides for support (i.e. the last slide deck).
Create a new source folder called test.
Within this folder, create a new JUnit Test Case called DVDTest.
You should be prompted to add JUnit4 to your build path. Do this.
A DVDTest.java file should be generated for you. Run this file and JUnit should report that you have 1 failure. Delete this generated test:
@Test
public void test()
{
fail("Not yet implemented");
}
Referring to your lecture slides for support, write the following tests:
Make sure that you use the setUp() method to setup your test data for each test method.
Are all your tests resulting in a green bar? If so, move onto the next step, otherwise revisit the tests and fix them.
In this practical, you will create a test class for Library.java (which will also test the XML loading and storing).
In this section, you may need to refer to your lecture slides for support (i.e. the fifth slide deck).
Within your DVDLibrary3.1 project, inside the test folder, create a new JUnit Test Case called LibraryTest.
A LibraryTest.java file should be generated for you. When you run this file, JUnit should report that you have 1 failure. Delete this generated test:
@Test
public void test()
{
fail("Not yet implemented");
}
Referring to your lecture slides for support, write the following tests:
Make sure that you use the setUp() method to setup your test data for each test method.
Are all your tests resulting in a green bar? If so, move onto the next step, otherwise revisit the tests and fix them.
The solution for the overall project can be found here.