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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值