JUnit is a Java package that implements unit testing. Eclipse provides grate tools to automate the creation of JUnit tests as well as provide a good interface to running the tests. Together these two tools make systematically testing your program very easy. In this lab we'll learn how to do this.
We'll be learning how to run JUnit tests on Eclipse. We've provided you with code that you must download from the class website to a new directory. There is a queue Interface, MyQueueI, a good implementation of a queue, MyGoodQueue, and a very bad implementation of a queue, MyBadQueue. MyBadQueue is written using two stacks.
Start by creating a new Java project in Eclipse from existing source:
JUnit is a very powerful package for creating unit tests to ensure your code is working correctly. An extension to JUnit allows us to partly automate the grading of your programming assignments.
We are first going to create a JUnit test to check if MyGoodQueue and MyBadQueue work correctly (you can guess which one doesn't work). MyGoodQueue uses the java.util.LinkedList to implement the queue. MyBadQueue uses java.util.Stack to implement the queue.
Create a JUnit to test the interface MyQueueI. Your junit must individually test all 4 methods described in the interface. Remember each test is independent, i.e. tests are not cumulative.
MyQueueI->New->JUnit Test Case fail() in each test and assert it correctly, see Assert Types for a list of possible asserts.The setUp() method will be run before each test is run allowing you to initialize your structures here. Use setUp() to first test the MyGoodeQueue implementation. To run the test go to the Run menu->Run As->JUnit Test
Once you are satisfied that it passes all tests change the code in setUp() to test the MyBadQueue.
Where's the error in MyBadQueue?
Feel free to ask your TA questions if at any step you are stuck. If you would like additional reference please follow this tutorial to create your JUnit tests.
Important: You may notice that some of these tests seem pointless because you must use other methods (of which you cannot guarantee the correctness of either) to test. For the sake of a simple introduction to JUnit we will ignore this important detail, but in general, this is a complicated and important part of JUnit testing.
So you've just realized that MyBadQueue doesn't work. The code is pretty convoluted but luckily you can uses the powerful Eclipse debugger.
MyBadQueue. Fill in code that will exercise each of the four methods.Fix MyBadQueue so that it passes the JUnit tests that you've written.