In Project 02, you implemented a set of test scenarios that were designed to assess whether a class (StudentCollection) properly implements its functionalities. Testing was conducted under black box guidelines - you had access to the executable for StudentCollection, but not to the source code, so you couldn't look at the code to determine exact test scenarios and had to rely on requirements documentation.

In Project 03 you are supplied with source code files for StudentCollection and StudentCollectionSpec and are to conduct "clear box" testing. There is one (1) (enum Project03Objectives {one}) specific objective for this project: assessment of the thoroughness of the unit tests implemented in Project 02 via use of a code coverage tool (specifically, JaCoCoverage).

Note that:

  • You are to test StudentCollection (the "target" class), and only that one class implementation.
  • You are to begin testing the supplied source code for StudentCollection by using your StudentCollectionTest as it existed at the end of Project 02.

You are supplied with one archive to be used as a resource in constructing the project associated with this lab, namely studentcollection.zip.

Important notes:

  • The StudentCollection implementation that you are testing in Project 03 is the same implementation that was tested in Project 02 - for Project 03, you have access to the source code for StudentCollection, not just the compiled .class file for StudentCollection.
  • You are to assess the thoroughness of your TestStudentCollection test class in testing the StudentCollection target class by using the JaCoCoverage plugin, then use the information provided by the plugin to improve thoroughness and/or document the rationale for why specific paths through the target class were not tested.

Project activities:

P1)Using Explorer, create a copy of your Project 02 project folder and (re)name the copy Project03ProjectYourLastName.

P2)Using Explorer, drill down to Project03ProjectYourLastName:

  • locate and remove the folders lib and Project02SuppliedJavadocs
  • locate the src folder, then expand the supplied studentcollection.zip archive into the src folder (when done correctly, the src folder will end up containing a studentcollection subfolder, which will contain two .java files).

P3)Open the project in NetBeans:

  • change the name of the project to Project03ProjectYourLastName
  • open project properties, select the Libraries category, and remove the library reference that was inserted in Project 02
  • verify that the project settings are correct (appropriate settings were specified in Lab 01)
  • perform a clean and build - the project should compile cleanly and contain no syntax errors, and specifically no reference errors

P4)Review the requirements documentation for the StudentCollection class being tested - while they have noted changed from Project 02, it's always best practice to refresh your knowledge of the requirements.

  • Reminder - (re)generate project Javadocs by right-clicking on the project name and choosing Generate Javadocs)

P5)Locate any untested paths in StudentCollectionTest, then revise TestStudentCollection and/or document the untested paths as appropriate.

  • Reminder - when creating a unit test, you are obligated to test all (100.0%) of the public methods within the target class
  • 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.
  • Execute the StudentCollectionTest file, determine if any test cases fail, and for all that do fail, proceed as follows.
    • If none of your tests from Project 02 failed, then none should fail here as you begin Project 03 - for all intents and purposes, you are testing the same logic here in Project 03 as you tested in Project 02. If no tests fail, that's a "good thing", and you can skip to the next step.
    • If any tests do fail, locate the cause of failure (which will be caused by incorrect setup coding and/or assessment of an expected result - remember, the code that you have been supplied has been "pre-tested" and determined to be correct).
    • Reminder - the JUnit report is hot-linked into the code, both StudentCollectionTest and now StudentCollection...
    • Determine the problem, repair it, and re-execute the test to verify that you corrected the problem.
    • For all cases where you alter / delete / add code in StudentCollectionTest, document what changes were made to correct the code - create a document named StudentCollectionTestScenariosAmendmentsYourLastName.docx by renaming your test scenarios from Project 02, and for each amendment indicate the method within StudentCollectionTest that was altered / deleted / added and the specific rational and nature of the amendment(s), e.g.
    • Unnecessary (redundant) test scenario - deleted "(insert deleted code here)"
    • Additional test scenario to improve code coverage - inserted "(whatever you added for code here)" to improve code coverage
    • Altered test scenario to improve code coverage - altered "(whatever you changed for code here)" to improve code coverage

P6)Assess the degree of code coverage that has been achieved

Determine and, if appropriate, improve the extent of code coverage your test cases have achieved.

  • Open the StudentCollection class, then open or give focus to StudentCollectionTest
  • Execute "Test with JaCoCoverage" (right-click project name, select Test with JaCoCoverage)
    • Note - JaCoCoverage can take a few seconds to complete, sometimes longer - if NetBeans' progress monitor (lower left corner) is active, then it's still working...
    • A report will be generated and presented in a web browser - for the time being, close the web browser report.
  • Give focus to StudentCollection and inspect the code to determine if there are any untested or under-tested statements (look for lines highlighted in yellow or red). If any such lines are located:
    • Design and implement additional test scenarios (and, if necessary, additional test cases) in order to increase the degree of code coverage. For all added test scenarios and/or test cases, insert appropriate documentation into the file named StudentCollectionTestScenariosAmendmentsYourLastName.docx (created and stored in the root folder of the project in step P5).
    • If you find that there are statements that cannot be fully tested (presumably because you cannot force a context in which they will be executed), document the statements in a Word document titled UndertestedStatementsYourLastName.docx (store at the root of the project folder). For each statement, include the name of the StudentCollection method that contains the statement, the actual statement (include a line number reference), and then explain why the statement cannot be fully tested.

If any of your additional test scenarios result in a failed test, repeat P5 until you have eliminated all failed tests and either covered all of the executable code or have documented why any under-covered or uncovered code cannot be fully covered.

At least once, use the JaCoCoverage report that is generated and displayed in a web browser to examine StudentCollection

  • Use the Element list (on the left) to navigate down and into the StudentCollection class
  • Pick a method or two with 100% coverage, clicking on each and inspecting the displayed code
  • For any methods that do not show 100% coverage, inspect each
  • The JaCoCoverage report is an alternate means of inspecting code for the degree of coverage exhibited by a unit test - while both NetBeans and the report use the same display highlighting conventions to indicate whether specific lines of code are thoroughly tested, the following differences should be noted:
    • The JaCoCoverage report includes statistical information that NetBeans does not - the degree of coverage (expressed as a percentage) can be determined at a glance
    • NetBeans allows you to inspect and then directly modify code and immediately re-execute tests, whereas the report is a simple static display
  • If the generated report gets annoying, it can be turned off via Tools->Options, Java tab, JaCoCoverage tab, and uncheck "automatically open generated JaCoCoverage HTML report in your browser". You can turn it back on using the same feature set.

P7)After finishing steps P4, P5 and P6 and before executing step P8, clear out unnecessary files from your project

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.