Skip to content

Commit 172a99e

Browse files
committed
Unity 的单元测试
1 parent 884c9b3 commit 172a99e

26 files changed

Lines changed: 139 additions & 0 deletions

Unit4Unity/Editor Test Runner/Assets/Editor.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
class NegativeHealthException : ApplicationException
7+
{
8+
9+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
public class Player{
6+
7+
public float Health { get; set; }
8+
9+
#region 正确的方法
10+
11+
public void Damage(float value)
12+
{
13+
Health -= value;
14+
if (Health < 0)
15+
{
16+
throw new NegativeHealthException();
17+
}
18+
}
19+
20+
public void Recover(float value)
21+
{
22+
Health += value;
23+
}
24+
#endregion
25+
26+
#region 错误的方法
27+
28+
public void DamageWrong(float value)
29+
{
30+
Health -= value + 1;
31+
}
32+
33+
public void DamageNoException(float value)
34+
{
35+
Health -= value;
36+
}
37+
#endregion
38+
}

Unit4Unity/Editor Test Runner/Assets/Editor/Player.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
using UnityEngine;
5+
6+
public class PlayerTest{
7+
8+
9+
[ExpectedException()]
10+
public void NegativeHealth()
11+
{
12+
13+
}
14+
15+
}

Unit4Unity/Editor Test Runner/Assets/Editor/PlayerTest.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unit4Unity/Editor Test Runner/Assets/Plugins.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unit4Unity/Editor Test Runner/Assets/Plugins/Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll.meta

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Unit4Unity/Editor Test Runner/Assets/Scenes.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)