单元测试01:nunit 安装与代码测试
生活随笔
收集整理的這篇文章主要介紹了
单元测试01:nunit 安装与代码测试
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.nunit 下載與安裝
a.下載
下載地址:?http://nunit.org/download/
b.添加到系統環境變量
解壓下載包后,添加兩個路徑到環境變量,如:
D:\nunitD:\nunit\nunit-console2.建立測試項目
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?
總結
以上是生活随笔為你收集整理的单元测试01:nunit 安装与代码测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL-04:数据内容操作-增删改查
- 下一篇: 单元测试02:Open-Cover安装与