单元测试01:nunit 安装与代码测试
生活随笔
收集整理的這篇文章主要介紹了
单元测试01:nunit 安装与代码测试
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.nunit 下載與安裝
a.下載
下載地址:?http://nunit.org/download/
b.添加到系統(tǒng)環(huán)境變量
解壓下載包后,添加兩個(gè)路徑到環(huán)境變量,如:
D:\nunitD:\nunit\nunit-console2.建立測(cè)試項(xiàng)目
a.建立class project
b.project 里reference添加 nunit.framework.dll。dll在下載包內(nèi)
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.測(cè)試
a.測(cè)試配置文件Test.nunit,修改assembly path=“....”
<NUnitProject><Settings activeconfig="Default" /><Config name="Default" binpathtype="Auto"><assembly path="./TestActPic.dll"/> </Config> </NUnitProject>b.執(zhí)行CMD
nunit3-console test.nunit --result=TestResult.xml?
總結(jié)
以上是生活随笔為你收集整理的单元测试01:nunit 安装与代码测试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: MySQL-04:数据内容操作-增删改查
- 下一篇: 单元测试02:Open-Cover安装与