In Project 01 you were supplied with Java interface files named StudentSpec and StudentCollectionSpec and were required to design a set of test cases for verifying that a class implementing StudentCollectionSpec implements that specification correctly based on the supplied documentation. As a reminder, StudentCollectionSpec was designed to specify the behavior of an implementing class intended to allow a client to store and manage a number of StudentSpec objects
For Project 02, the functional objective is to implement a set of JUnit test cases based on test scenarios created during Project 01 in combination with test scenarios provided by the instructor in order to demonstrate that a supplied class (StudentCollection) correctly implements all of its requirements (those specified by the supplied StudentCollectionSpec as well as any additional requirements specified by the supplied StudentCollection). Note that:
- You are to test the StudentCollection implementation that is provided, and only that one class implementation (that is, testing of Student is NOT part of this Project! Don't go there!).
- You are to make use of the set of test scenarios that you designed in Project 01, except that any test scenarios specified in the file Project02-TestScenarios-Supplied.docx must be implemented as specified - you are required to use the set of test scenarios supplied by the course instructor. Think of the scenarios in Project02-TestScenarios-Supplied.docx as "overriding" equivalent scenarios in your test case document. Note that Project02-TestScenarios-Supplied.docx does not supply a complete set of test scenarios, so you will be expected to implement at least some of your test scenarios depending on the thoroughness of your test scenarios from Project 01, you may find that additional test scenarios will be designed and implemented.
You are supplied with a number of resource files, in particular two archives (Project02ProjectNameless.zip and studentcollection.zip) to be used as resources in constructing the NetBeans project associated with this project. Make sure that you have both available when you begin this project. A third file, Project02-TestScenarios-Supplied.docx, contains a set of test scenarios that you will be implementing within a StudentCollectionTest class. A fourth file, Project02SuppliedJavadocs.zip, contains formal javadocs for all Java components of the project. A final file, TranslatingScenariosIntoCode.docx, provides a set of strategies for translating test scenarios into JUnit code.
Project activities:
P1)The file Project02SuppliedJavadocs.zip contains javadocs for all Java elements of this project, explicitly including javadocs from StudentCollectionSpec and from the implementation of StudentCollection that is being tested. To view the documentation, extract the contents of the archive onto your hard drive, then drill down to Project02SuppliedJavadocs\index.html and double-click. Do not extract the file into the project folder extracted in the next step - anywhere else is acceptable. Note that you are likely to refer to this documentation multiple times saving a shortcut to Project02SuppliedJavadocs\index.html onto your desktop will save some time.
P2)Project02ProjectNameless.zip contains a NetBeans project that is to serve as the starting point for this project.
- Expand the archive onto your hard drive - expansion will result in a folder named Project02ProjectNameless containing a NetBeans project named Project02ProjectNameless.
- Open the project in NetBeans, then change the name of the project and its enclosing folder by right-clicking the project name in the project pane and choosing Rename; replace "Nameless" at the end of the project name with the usual LastName, e.g. resulting in Project02ProjectKnuth.
- Expand the Source Packages and Test Packages trees so that the contents of all packages are displayed in the Projects pane: note that there is no file named StudentCollectionSpec.java or StudentCollection.java anywhere in the source tree. At no point in this project are you to insert source code for either into this project!!! Also, expand the Libraries tree.
- There will be error badges manifesting in the project pane - ignore them for the time being.
- The error badges are present because in its current state, the project does not contain a version of StudentCollectionSpec or of StudentCollection, and all of the badged components reference these classes. The next step will resolve the problem.
- Close the project (it is a profoundly bad idea to attempt the next step while the project is open). There is no need to close NetBeans (but doing so would not hurt).
P3)The zip archive named studentcollection.zip is supplied as a resource to be used by this project. This archive contains compiled Java code (that is, byte code), specifically, the class files resulting from compiling a Java interface named StudentCollectionSpec and a Java class named StudentCollection that implements the StudentCollectionSpec interface; both components are in a package folder named studentcollection. You must incorporate this archive into your project as follows:
- As indicated at the end of the previous step, make sure that your project is NOT OPEN IN NetBeans WHEN YOU BEGIN THIS STEP.
- Use Explorer to browse to your project folder. In the project folder, at the same level as the src folder, create a folder named lib (the spelling and case are specific - do not use a different name).
- Copy the supplied studentcollection.zip archive into the lib folder (do not expand the archive!).
- Copy the supplied Project02SuppliedJavadocs.zip archive into the lib folder (again, do not expand the archive!)
- Open the project in NetBeans.
- Right-click on the project's "Libraries" folder in the project pane, choose Add Jar/Folder, then browse into the lib folder of the project and double-click the studentcollection.zip entry. Make sure that the Relative Path option is selected! Click Open to finish.
- Right-click the Libraries\studentcollection.zip entry, choose Edit, then for the Javadoc path browse to Project02SuppliedJavadocs.zip in the lib folder of the project. Click OK to finish.
- Open the Project Properties dialog; in the Sources category, if the Test Packages Folders is blank, register the "test" folder (add folder, browse to the test folder in the project folder for this project, click Open).
- When you are finished, your details of the project pane contents should look like the following. Note that all of the error badges observed in the previous snapshot have disappeared
- Open the StudentGUI.java class, put the cursor on a reference to StudentCollection (line 33 works as well as any), then use Alt+F1 to view the javadocs for the studentcollection package. Executing this step provides an alternate means of accessing the studentcollection package javadocs, without needing to leave the IDE.
P4)Verify that you have properly constructed your project:
- perform a "clean and build" - this should result in a clean compile with no syntax errors.
- launch the project via the Run Project button - the following JFrame should appear see image.
- If any syntax errors are generated, or launching the project fails to cause the specified JFrame to display, go back and check steps P1 through P3; if the problem cannot be resolved, zip the project and send it to your instructor.
- Open the StudentCollectionTest.java file and execute it (right-click, Test File) - if the project is set up correctly, you will see a Test Report that indicates that all test cases fail for one reason or another (this is to be expected, because the supplied StudentCollectionTest file is a skeleton created by NetBeans).
P5)Open the supplied StudentCollectionTest file, then implement and execute the test scenarios provided by the course instructor.
- Place a copy of the test scenarios provided by the course instructor (Project02-TestScenarios-Supplied.docx) in the Project02Project LastNameInitialOfFirstName folder; also, place a copy of the test scenarios that you created in Project 01 in the same location.
- For each of the test scenarios (reminder - test scenarios that are supplied by the instructor "override" (replace) any equivalent test scenarios for the relevant methods that were created in Project 01), write code as needed in the appropriate test case to implement the specified setup, invocation, and assessment operations. Each test scenario's block of code should be separated from other scenario blocks in a test case via a visually-obvious separator comment line, and the setup, invocation, and assessment sub-blocks should be separated by a blank line (follow the style found in the StudentVerifiedViaJUnit example).
- The supplied file TranslatingScenariosIntoCode.docx provides a detailed strategy for translating test scenarios into unit testing code, with examples of JUnit code syntax; additional techniques and examples can be found in the white paper accompanying Project 01.
- Reminder - to execute a JUnit test, give the StudentCollectionTest file focus in the editor, then right-click and choose Test File (or type CTRL+F6, or click the Test File button ( ) ) - a Test Results tab will appear in the output pane. Any unsuccessful tests will be marked in red as "failed" (a JUnit assertion proved to be false) or caused an ERROR (something that was attempted within the project's executable code caused an uncaught exception). Unsuccessful tests can be expanded, and line references in the expanded report are hot-linked so that you can link directly into the StudentCollectionTest source code to determine what was being attempted when the test failed. You will not be able to link into the StudentCollection class for the hopefully-obvious reason that there is no source code available for the StudentCollection class, just byte code.
- Remember that this is an exercise in black box testing - this will have a significant effect on how you deal with a failed test case. With clear box (white box) testing, when a test fails you can look at source code to determine if the problem is within the class being tested or within your test scenario implementation. With black box testing, there is no source code to examine, so if a test case fails, you must look at the test case carefully to determine if the designed setups, assert() invocations, and expected results within the test scenario are appropriate and have been implemented correctly.
- If you think that you need additional test scenarios, add them to the test cases document Project02-TestScenarios-Supplied and highlight them in yellow, then implement the additional test scenarios in your StudentCollectionTest file.