README.md 1.97 KB
Newer Older
jang dong hyeok's avatar
.    
jang dong hyeok committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Unity Source Control Tests
This project contains the tests for the window/UI of this collab client.

## Overview
This is the structure of the project:
```none
<root>
  ├── .tests.json
  └── Collaborate
      └── Editor/
          ├── Components/
          ├── Models/
          ├── Ppresenters/
          ├── Scenario/
          ├── UserInterface/
          ├── Views/
          └── Unity.CollabProxy.EditorTests.asmdef
```

Each directory features tests and mock classes for classes in the editor code.

## Tests
To run the tests, use the Unity Test Runner from within the Unity Editor. Unity Test Runner documentation is [here](https://docs.unity3d.com/Manual/testing-editortestsrunner.html).

## Adding a Test
While 100% coverage is hard to achieve, tests should be added with each new feature to ensure coverage either remains constant or increases.

With that out of the way, tests are in the typical C# format with a function with a `[Test]` decorator. Below is an example of a test taken from `Editor/Models/ChangesModelTests.cs`
```csharp
[Test]
public void ChangesModel_NullSourceControlEntries_EmptyResultLists()
{
    var model = new TestableChangesModel();
    model.UpdateChangeList(new List<IChangeEntry>());

    var fullList = model.GetAllEntries();
    Assert.AreEqual(1, fullList.Count);
    Assert.IsTrue(fullList[0].All);

    Assert.AreEqual(0, model.GetToggledEntries().Count);
    Assert.AreEqual(0, model.GetUntoggledEntries().Count);

    Assert.AreEqual(0, model.ToggledCount);
}
```
For documentation on the testing library, look at the NUnit [documentation](https://github.com/nunit/docs/wiki/NUnit-Documentation) over at GitHub. Unity Test Runner is a superset of NUnit and the documentation for that is [here](https://docs.unity3d.com/Manual/testing-editortestsrunner.html).

To access private/internal classes, creating a subclass and marking the parent fields as protected/internal will allow them to be used in testing.