A7: Introduction to JUnit
DUE:
11:59PM, Thursday 9 November 2017
30 points
1. Goal
The goal of this assignment is to practice writing unit tests with JUnit. This assignment will also require everyone to use parameterized JUnit tests and JUnit theories.
2. Tasks
You will test some methods of the LinkedHashMap class that is provided in the Java library inside the package java.util. Click here to find the documentation. You will implement your test methods inside three separate files because the parameterized and theory tests require separate JUnit runners. The file names are TestLinkedHashMap (regular JUnit tests), TestLinkedHashMapParameterized.java (parameterized JUnit tests), and TestLinkedHashMapTheory.java (JUnit theory tests). The three test classes must be in a package called a7. Put your name in a comment at the top of each file.
Each test method should focus on testing one aspect of a single method under test. It's possible that testing that aspect requires multiple assertions. However, you should not test multiple aspects within one test. For example, to test the isEmpty() method, you must not use both an empty and a non-empty LinkedHashMap instance in the same test method.
Test the following methods of the LinkedHashMap<K, V> class.
- boolean isEmpty (This method is inherited from the HashMap class. Thus, you need to look at its specification in the documentation of HashMap.)
- V get(Object key)
- Set keySet() (This method returns a set of keys in the same order as the order they were inserted.)
- V put(K key, V value) (This method is inherited from the HashMap class.)
- void putAll(
K key, V value Map<? extends K,? extends V> m) (This method is inherited from the HashMap class.)
-
boolean V remove(Object key) (This method is inherited from the HashMap class.)
You must write at least two test cases for each method to exercise different conditions (e.g., forcing true/false return values, getting a value with a valid and invalid key, etc). At least one of these tests must be parameterized and at least one other test must use JUnit theories.
2. Submission
- Zip the a7 folder containing the source test files (not class files) into a file called TestLinkedHashMap.zip.
- Submit the TestLinkedHashMap.zip file in Canvas.
- Important Reminder: You may use material from the book or other sources in your answers. However, you must cite your sources properly. Any verbatim quotations must be enclosed in quotation marks, with page numbers indicated. You will receive severe point deductions if you use material from the text or other sources that is not properly cited.