zoukankan      html  css  js  c++  java
  • NUnit测试工具示例

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NUnit.Framework;

    namespace TestModelByNUnit
    {
        [TestFixture]
        
    public class MyClass2
        {

            [TestFixtureSetUp]
            
    public void OpenConnection()
            {
                
    //open the connection to the database
                
    //整个TestFixture只在开始的时候触发一次
            }

            [TestFixtureTearDown]
            
    public void CloseConnection()
            {
                
    //close the connection to the database
                
    //整个TestFixture只在结束的时候触发一次
            }

            [SetUp]
            
    public void CreateDatabaseObjects()
            {
                
    //insert the records into the database table
                
    //每个Test开始时触发一次
            }

            [TearDown]
            
    public void DeleteDatabaseObjects()
            {
                
    //remove the inserted records from the database table
                
    //每个Test结束时触发一次
            }

            [Test]
            
    public void Sum()
            {
                Assert.AreEqual(
    31 + 2);
                Assert.AreEqual(
    "Hello World1""Hello World");
            }

            [Test]
            [Category(
    "数字测试")]
            
    public void Sum1()
            {
                Assert.AreSame(
    "Hello World""Hello World");
            }

            [Test]
            [ExpectedException(
    typeof(DivideByZeroException))]
            [Category(
    "异常测试")]
            
    public void Sum2()
            {
                
    int zero = 44;
                
    int b = 1 / zero;
                Assert.Fail(
    "这是失败的信息");
            }

        }
    }

    http://www.nunit.org/

    示例详细:

    http://confach.cnblogs.com/archive/2005/06/20/177817.aspx

  • 相关阅读:
    一致性哈希算法
    Discourse 的标签(Tag)只能是小写的原因
    JIRA 链接 bitbucket 提示错误 Invalid OAuth credentials
    JIRA 如何连接到云平台的 bitbucket
    Apache Druid 能够支持即席查询
    如何在 Discourse 中配置使用 GitHub 登录和创建用户
    Apache Druid 是什么
    Xshell 如何导入 PuTTYgen 生成的 key
    windows下配置Nginx支持php
    laravel连接数据库提示mysql_connect() :Connection refused...
  • 原文地址:https://www.cnblogs.com/wucg/p/1838631.html
Copyright © 2011-2022 走看看