Directions: This project has 2 tasks that will guide you through unit testing and code coverage.

Goals: The intention of this project is to become more familiar with unit testing using JUnit (i.e., the hard way) in conjunction with code coverage, generating unit tests for JUnit using EclEmma and Google CodePro (i.e., the easy way) as well as continuing to familiarize you with several software development tools (Eclipse, Git and GitLab).

Language/Environment Requirements: Java within the Eclipse IDE using JUnit 4.12, EclEmma 2.3.3 and Google CodePro Analytix should be used for this project.

Task 1 - Code Coverage Vending Machine. The ability to assess how "good" your unit tests are in covering your source code is important. In this task, we will use the EclEmma Eclipse plugin (http://www.eclemma.org/) to determine the code coverage for the unit tests you developed in the previous project for the Vending Machine application. To install the EclEmma plugin if it is not already included in your Eclipse distribution, you should use the same process for installing Eclipse plugins as we have used all semester and search for EclEmma in the Eclipse Marketplace. EclEmma is pretty straight-forward to use, but in case you need further help, see the User Guide at http://www.eclemma.org/userdoc/index.html.

We will use the VendingMachine code and unit tests you created in the previous project. First, refactor the package name to indicate it is Project 3 (not Project 2!). With the VendingMachine code and the unit tests you came up with from the previous project, run the EclEmma coverage tool by right clicking on the project, selecting Coverage As and then selecting JUnit Test. Note that you can achieve the same thing by running the ElcEmma coverage tool icon in the toolbar. This will run your test cases against the source code and present a coverage report describing the code coverage. If no results were displayed, you may have to enable the view by select in the menu Window, then Show View, then Other, expand the Java folder and select Coverage. If your existing test cases do not achieve 100% code coverage, you should refine/add test cases and rerun EclEmma until you have 100% coverage on the VendingMachine.java and VendingMachineItem.java source files. Once you have 100% code coverage, generate a test report by right clicking anywhere in the Coverage view, select Export Session, then Java > Coverage Report and generate an HTML report named TestReport1.html that should be included (along with the dependent files) in a Test Report folder within your VendingMachine project.

Task 2 - Generating Unit Tests Vending Machine. Now that you understand unit testing and you've learned how to develop unit tests manually, we can take advantage of tools that automatically generate unit tests by analyzing the code. To do so, we will use Googles CodePro Analytix. First, be warned - Google CodePro was an awesome tool that is now no longer supported, we will install it in a very hacky way, and it is buggy in the current version of Eclipse. But, it is still (as far as I know) still the best, free Junit test generation (and other things well use later) tool for Eclipse.

To install the CodePro Analytix plugin, we will have to follow a slightly different process than the previous plugins because Google CodePro is not in the Eclipse Marketplace for our version of Eclipse, nor is it (seemingly) anywhere else online. I have provided the .zip file of the plug in on Blackboard under the Project 3 folder. Download this and save it locally (do not unzip it!). To install Google CodePro, you should go to the Help > Install New Software and then click on the Add button. In the Name field, provide "Google CodePro" and for the Location field, click on the Archive button and point to the downloaded .zip plugin file I provided. This will guide you through the installation process, which is also described at https://dzone.com/articles/codepro-integration-eclipse. (Note that this plugin is targeted at an earlier version of Eclipse but should work mostly fine with the more recent versions). Google CodePro is pretty easy to use, you can familiarize yourself with the CodePro tool from the new CodePro menu in Eclipse and selecting the Welcome and Cheat Sheets options and reading through the documentation.

As we did previously, we will use the empty VendingMachine.zip project that I have provided on Blackboard. To be able to compare to the experience of manually developing JUnit test cases, you should import the VendingMachine.zip into a new project named Vending Machine 2. Again, make sure that you refactor the package name to ensure it indicates it is Project 3.

Before generating the test cases, you should try some of the other CodePro features, such as Analyze Dependencies and Compute Metrics, which will calculate the Cyclomatic Complexity (among other things). See the CodePro > Cheat Sheets for how to generate these reports. As mentioned, CodePro can also generate JUnit test case code. To do so, right click on the package containing the VendingMachine.java and VendingMachineItem.java source files, select CodePro Tools and then Generate Test Cases. This will generate pretty extensive unit tests for all source files (probably in a separate VendingMachine2Test project - you can copy them into your project). Examine the generated unit tests, execute them, run the EclEmma coverage tool (from Task 1) and generate an HTML report named TestReport2.html that should be included (along with the dependent files) in a Test Report folder within your VendingMachine2 project.

While the unit test coverage is likely not quite 100%, it is pretty extensive and much easier (and quicker!) than writing the test code manually! With this generated code, you should augment it to, again, achieve 100% coverage of the 3 source files; to do so, you can either add test cases programmatically or using the tabular test case creation VeVprovided by Google CodePro. Once you have 100% code coverage, generate an HTML report named TestReport3.html that should be included (along with the dependent files) in a Test Report folder within your VendingMachine2 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.