Unit Tests

Unit tests are automation tests that are prepared for when making changes to the application can increase awareness to the unexpected change of application behaviour and most importantly, prevent bug

Briefing

In unity, unit tests separated into PlayMode and EditMode tests, PlayMode tests is capable of automate any test that required Monobehaviour features, it runs on as it name suggest, Play Mode while EditMode tests is run under Editor where Monobehaviour scripts cannot be tested without problem. In this case, PlayMode is perfect for testing GUI scripts while EditMode is much more suitable for testing game logic, as for this package. In order to open Unit Tests tab, named Test Runner in Unity, see the gif below.

PlayMode Tests

Only one test is prepared for PlayMode, it is for testing PGN text file imported from elsewhere, to test if our chess engine can run them without problem.

To run the test, double click the PGNGUITextFilesTests test highlighted in blue on the image above. The results are as below.

What does the test automation do on the background?

1) It will start the scene ChessPGN in PlayMode.

2) Change the PGN Game dropdown to index 1, which is Micheal Adams in this case.

3) Then it will hit start button where all of the text in PGN text file will be converted to game data.

4) From there, it will exhaustively select each matches available in the game from the PGNMatchesDropdown UI, just like how we would change PGN matches from the scene. It will also hit the "<" button until no more moves left to be undone before moving on into next match.

Note that all of the steps above will not be visible to the eyes but Unity Editor will freeze the screen just to perform the test in highest speed possible.

**There will be no any error provided if PGN text files passes our engine standard.

Customize PGNGUITextFilesTests to test newly imported PGN text files

Open the file named PGNGUITests. There are three functions being prepared on this test, only one of it can be run at one time. It is recommended to test all newly imported PGN text file just once, so that the PGN scene can be free from bug that might be caused by PGN text file. To add new PGN text file to the PGN Game dropdown see ChessPGN page.

1) PGNFullTest - For testing all PGN text files that's selectable through PGN Game dropdown(image above) in ChessPGN scene, in bulk. This test is not recommended as it will freeze the screen for so long if there's too many total matches to be tested, and it also repeat the tests for all dropdown that had been previously tested. Unless all of the dropdown hasn't been tested previously, otherwise use 2) function.

2) **PGNMatchesTest(Default) - For testing one full PGN text file, the pgnDropdownIndex variable in this function can be changed. The integer value is based on the PGN Game dropdown index. Like 1 is Micheal Adams and 2 is Magnus Carlsen. This is the recommended function to be used at all time.

3) PGNSingleMatchTest - For testing one single match from a specific PGN text file. It is used only once error had been identified from a specific match. Once error occurs while running other test functions, we can see from the debug log which match number it stops at +1, there's where the problematic match number can be identified and be used in matchTest variable.

To switch function to be executed during the test. In PGNGUITextFilesTests function, make the desirable choice uncomment while others two in comment state.

EditMode Tests

The EditMode tests are prepared for probably programmers who would modify game logic code, namely scripts contained in Mechanism namespace. Most of the time people who perform tests in this section know what they are doing.

Last updated