我想對這樣的測驗進行分組:

為了得到這個截圖,我使用了 TestCases,但它們并不真正適用于我的需求。
顯然我不想要這個:
[TestCase(TestName = "ShouldDoSomething")]
[TestCase(TestName = "ShouldDoSomethingElse")]
public void OnJoinRoom()
{ ... }
我想要這樣的東西:
[TestGroup("OnJoinRoom")]
public void ShouldDoSomething()
{ ... }
[TestGroup("OnJoinRoom")]
public void ShouldDoSomethingElse()
{ ... }
我不認為使用子類是一種選擇,因為測驗取決于 TestFixture 類中使用的 SetUp 方法。
uj5u.com熱心網友回復:
在 NUnit 中,TestFixtures 用于對測驗進行分組以及提供通用設定。跨多個TestFixture提供通用設定的常規方法是擁有一個通用基類,例如
public class CommonBase
{
[SetUp]
public void CommonSetUp() { }
}
[TestFixture]
public class OnJoinRoom : CommonBase { }
[TestFixture]
public class OnLeaveRoom : CommonBase { }
筆記:
- 將所有測驗放在派生類中
TestFixture屬性當然是可選的,但不要放在基類上。- 如果您愿意,基類可以是抽象的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/519996.html
標籤:C#unity3d单元
上一篇:我不能用c#寫json檔案
