单元测试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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章