The Repository contains a maven project with queue extended from Princeton's Intro to programming sample. You are the developer who is supposed to write the unit test case for this class. The client required a simple Java class which implements the Queue Data structure. As the developer you wrote the code and the same was pushed in this repository.
The problem: The "dequeue" method has a bug : The developer has forgot to throw an exception when the queue is empty.
Create Unit test cases for the code in this repository. The tests should have 100% instruction & branch coverage for both constructors, enqueue, dequeue, peek, length, isEmpty, removeAll methods.
Upload Results Copy the code coverage report and attach the same with your submission.
Write a test case which exercises the program to find the fault in the dequeue method. Bug : The class does not throw an exception when dequeue function is called on an empty queue. Remember the intended behaviour of the dequeue method in a queue data-structure is throw an exception if it is called on a queue is empty. You find the problem is that: someone commented a part of your code (Line 147 & 148) after you pushed the same.
Note after writing this test case:
mvn test
will state that one of your test case is failing
Hint : Your test case would expect a NoSuchElementException, but that is not thrown hence this test case will make your mvn test fail, and this the expected behaviour.
Upload Results : Upload your code and test cases to the repository and the blackboard.
- Have 100% instruction & branch coverage for both constructors, enqueue, dequeue, peek, length, isEmpty, removeAll for Queue Class.
- Annotations of JUnit are to be used.
- Test cases must be complete & should check for expected outcome. (except for the "toString" method). An example would be, after the dequeue method is called on the queue, ensure that the length of the queue decreases by one. Or that when "peek" method is called, the returned value is the expected element.
- You should have atleast 1 failing test which reveals the bug in the enqueue method disclosed earlier.
Please submit the following on blackboard:
- Github Repository link.
- Screenshot of instruction coverage after Task 1.
- Screenshot of instruction coverage after Task 2.
- zip the project folder
The project is tested on adoptium JDK-17 LTS but any JDK-17 flavour should work just fine. This assignment assumes you have knowledge of Java Classes and have a working installation of JDK. P.s. Java-8 might work as well, but is not tested!
You can check the current code coverage using the following ways:
To Run tests and generate coverage reports :
mvn jacoco:prepare-agent test jacoco:report
or just
mvn test
- Location of reports : target/site/jacoco/index.html
- Screenshot of a sample report
This repo is configured to automatically generate a new commit after you push code online! This commit will generate badges reflecting the current test coverage of code. You can just push code to github then wait for the github action to finish which should update the badges automatically!
Please do git pull
after the bot has updated your repo with badges
This helps everyone stay on the same page.