Today you will start testing Project 2: Tablut. If you have not already, take a look at the spec here.
In this lab, we will go over how to test your project. There will be nothing to submit for this lab, and feel free to take this lab section as time to ask your TA and/or academic interns questions about the project. The relevant file
TablutTests.java will be under your
lab11 folder. Copy this file into tablut folder of your Project 2 directory. Feel free to use the tests that you write in this lab as part of the tests you submit for your project.
C. Unit Testing
While we suggest you write unit tests for most or all of the methods you implement, we will be focusing on writing tests for the
legalMoves method in your Board class.
TablutTests.java, we provide you with skeleton for two tests that you can use to test your
legalMoves method in your Board class. The test begins by initializing a new Board based off of
initialBoardState, placing Pieces in that Board, and then calling
legalMoves. Both the tests should pass successfully for correct implementation of
When you write your own unit tests, it is a good idea to think of many different cases of your method and where your methods could break. Can you think of other cases that you should be testing for this method? Try writing more assertions and/or another test for
legalMoves that accounts for those. You can also create different board states similar to
initialBoardState and run these tests on it to verify correctness of your implementation of
legalMoves method. Ask your TA or an academic intern if you're not sure what cases to consider.
D. Integration Tests
To obtain the
proj2/testing/test-tablut file to run your integration tests (if you do not have it), first commit all your changes and then run:
git fetch shared
git merge shared/proj2
See the project spec as well as the provided example testing files under
proj2/testing in your repo for more information on how to use this.
These tests are useful to see that your entire game is working - the integration tests model a game being played on standard input.
00-initial-1.in checks if the initial board is correct.
00-simpmoves-1.in simulates a manual white player and checks if move command is working correctly.
Some suggested ways of writing more tests:
- Play an entire game against the staff Tablut program, and replicate all your moves and the staff moves as manual players in an integration test. Make sure that you are able to run through the whole sequence of moves without errors.
- Observe a game between two automatic players in the staff solution. Replicate all but the last couple of the moves in a test, and then make both your players automatic. Does you AI find a similar win?
That's it! There will be nothing to submit for this lab.