1.nunit 下載與安裝
a.下載
下載地址: http://nunit.org/download/
b.添加到系統環境變量
解壓下載包後,添加兩個路徑到環境變量,如:
D:\nunit
D:\nunit\nunit-console
2.建立測試項目
a.建立class project
b.project 裏reference添加 nunit.framework.dll。dll在下載包內
c.代碼編寫
namespace TestActPic
{
[TestFixture]
public class TestActPic
{
private XmlDocument xmlDocument = new XmlDocument();
private ActConfig config = new ActConfig();
[SetUp]
public void Setup()
{
Trace.Listeners.Add(new TextWriterTraceListener("log.txt"));
Trace.AutoFlush = true;
this.xmlDocument.Load(@"TestActPic.xml");
}
[Test]
public void TestConstructorRight()
{
// .......
ActBase CapPic = new ActePic(config);
}
[Test]
[ExpectedException]
public void TestConstructorWithoutWindows()
{
config.Node = xmlDocument.SelectSingleNode(@"//TestConstructor/ConstructorWithoutWindow/Act");
Base CapPic = new ActPic(config);
}
[Test]
public void TestWrong()
{
// Assert.AreEqual("test", this.title);
DriverDiretory testr = new DriverDiretory(testPath[1]);
List<string> list = new List<string>();
Assert.AreEqual(false, testr.GetAllDriver(ref list));
}
}
}
3.測試
a.測試配置文件Test.nunit,修改assembly path=“....”
<NUnitProject>
<Settings activeconfig="Default" />
<Config name="Default" binpathtype="Auto">
<assembly path="./TestActPic.dll"/>
</Config>
</NUnitProject>
b.執行CMD
nunit3-console test.nunit --result=TestResult.xml