欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

单元测试01:nunit 安装与代码测试

发布时间:2023/12/4 编程问答 49 豆豆
生活随笔 收集整理的这篇文章主要介绍了 单元测试01:nunit 安装与代码测试 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

1.nunit 下载与安装

a.下载

下载地址: http://nunit.org/download/

b.添加到系统环境变量

解压下载包后,添加两个路径到环境变量,如:

D:\nunitD:\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

 

总结

以上是生活随笔为你收集整理的单元测试01:nunit 安装与代码测试的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。