Create JUnit tests for the Stack interface.
- Create an IDE project and add ku/util/Stack.java to your project "src" tree.
- In the source tree, create a dummy stack with do-nothing methods. Eclipse can quickly do this for you.
- Real stacks have a capacity set via the constructor. So you may add a
DummyStack(int capacity)
constructor to match this.
- Real stacks have a capacity set via the constructor. So you may add a
- Create a separate source tree named "test" for test code (best practice).
- In
test/ku/util
create a StackTest class that tests the Stack methods. For now use your dummy stack.- Most of the tests will fail. This is usual.
- Download and add
StackFactory.jar
to your project. - In StackTest, create a real stack using:
Stack stack = StackFactory.makeStack( capacity );
- StackFactory produces 3 kinds of Stack. The default is type 0 (ArrayStack). To test a different stack type, add this code:
@Before
public void before() {
StackFactory.setStackType( 1 ); // type = 0, 1, or 2
}