> For the complete documentation index, see [llms.txt](https://freedom-developer.gitbook.io/the-chess/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://freedom-developer.gitbook.io/the-chess/unit-tests.md).

# Unit Tests

## 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.

<figure><img src="/files/7ypb0A14cn2kJfxJyCM0" alt=""><figcaption></figcaption></figure>

## 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. &#x20;

<figure><img src="/files/rqQpwuRYuOzoSSxdB36S" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/7rbpm6XXNWeoOQgsNMgy" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/wHIgx9ZBVGLdkhcse4B8" alt=""><figcaption></figcaption></figure>

### 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.&#x20;

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.&#x20;

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](/the-chess/scenes-details/chesspgn.md) page.

<figure><img src="/files/MS7FOMgKhvThfquNLpkP" alt=""><figcaption><p>PGN Game dropdown</p></figcaption></figure>

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.

<figure><img src="/files/byRuES3Mp0WDyRV2slTs" alt=""><figcaption></figcaption></figure>

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.**

<figure><img src="/files/mByMGAhAotFFkWHqFpKT" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="/files/PC2ctkhwx0kt7Cm8Ci6H" alt=""><figcaption><p>PGNGUITextFilesTests function</p></figcaption></figure>

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.

<figure><img src="/files/64cMiGKJJ2q9qWCQOdXm" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://freedom-developer.gitbook.io/the-chess/unit-tests.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
