-
Notifications
You must be signed in to change notification settings - Fork 1
StaffBenefits
The StaffBenefits subsystem is a new feature for the Enterprise Resource Planning (ERP) system of the company. The development team claim that it is ready. Select a criteria and create unit tests for each of the methods at StaffBenefits and Utils classes using JUnit 4.
Tooling: Install them: Eclipse menu -> Help -> Eclipse Marketplace
- Control Flow Graphs: Sourcecode Visualizer 4.3.3
- Coverage: EclEmma Java Code Coverage 2.2.1,
Alternatively, they can be installed through the marketplace by droping the Install button inside the running Eclipse
- https://marketplace.eclipse.org/content/sourcecode-visualizer
- https://marketplace.eclipse.org/content/eclemma-java-code-coverage
Create a Test suite and analyze the coverage
Analyze the coverage of the tests with EclEmma
If bugs are found through your tests, try to localize them and suggest a solution
Frequently asked questions
-
How can I import JUnit to use @Test etc.? Right click the project and click on Properties. Then, in the Libraries tab click on Add Library... and select JUnit.
-
Why Assert.assertEquals(double expected, double actual) is deprecated? Use assertEquals(double expected, double actual, double delta) instead. A delta of 0.0 means that they must be exactly the same. If you put 0.0001 then you are allowing a margin of error.
-
Is it possible to automatically test it if the method requires user input? Yes, search how to simulate user input in java. It is very few lines of code.
-
The test is never finishing? It seems like an infinite loop somewhere... You can add a timeout to the test @Test(timeout=1000). It is on milliseconds. If the test takes more than this time to complete, then it is considered as a failure.
-
I have to click on a window for the test to finish? Normally tests are run as part of a continuous integration process and this automatic process will be blocked if there are user interfaces like this. We will not cover this aspect in this exercise, but, as workaround, you can modify the method to include a boolean parameter to show or not windows to the user.