zoukankan      html  css  js  c++  java
  • 使用VisualStudio进行单元测试之四 顺序测试

    前文中所提到的测试都是针对一个方法进行的独立测试,即使是同事测试多个方法,他们之间也没有影响。但是在实际的生产过程中,更多的情况是方法与方法之间是存在相互的逻辑关系的,所以也就有了今天要介绍的顺序测试。

    顺序测试,顾名思义,就是按照预先设定的顺序来测试一系列的方法。
    1. 首先还是展示一下要进行测试的代码
       
          public class Mathmatics
          {
              public static int Add( int a, int b)
              {
                  return a + b;
              }
              public static int Dec( int a, int b)
              {
                  return a - b;
              }
       
              public static int Div( int a, int b)
              {
                  return a / b;
              }
       
              public static int Mul( int a, int b)
              {
                  return a * b;
              }
          }
    2. 生成各个方法对应的测试代码
       
              /// <summary>
              /// A test for Add
              ///</summary>
              [ TestMethod ]
              public void AddTest()
              {
                  int a = 1; // TODO: Initialize to an appropriate value
                  int b = 2; // TODO: Initialize to an appropriate value
                  int expected = 3; // TODO: Initialize to an appropriate value
                  int actual;
                  actual = Mathmatics . Add(a, b);
                  Assert .AreEqual(expected, actual);
              }
       
              /// <summary>
              /// A test for Dec
              ///</summary>
              [ TestMethod ]
              public void DecTest()
              {
                  int a = 2; // TODO: Initialize to an appropriate value
                  int b = 2; // TODO: Initialize to an appropriate value
                  int expected = 0; // TODO: Initialize to an appropriate value
                  int actual;
                  actual = Mathmatics . Dec(a, b);
                  Assert .AreEqual(expected, actual);
              }
       
       
              /// <summary>
              /// A test for Div
              ///</summary>
              [ TestMethod ()]
              public void DivTest()
              {
                  int a = 1; // TODO: Initialize to an appropriate value
                  int b = 1; // TODO: Initialize to an appropriate value
                  int expected = 1; // TODO: Initialize to an appropriate value
                  int actual;
                  actual = Mathmatics . Div(a, b);
                  Assert .AreEqual(expected, actual);
              }
       
              /// <summary>
              /// A test for Mul
              ///</summary>
              [ TestMethod ()]
              public void MulTest()
              {
                  int a = 0; // TODO: Initialize to an appropriate value
                  int b = 0; // TODO: Initialize to an appropriate value
                  int expected = 0; // TODO: Initialize to an appropriate value
                  int actual;
                  actual = Mathmatics . Mul(a, b);
                  Assert .AreEqual(expected, actual);
              }
    3. 创建顺序测试
      在测试项目上添加新项--顺序测试(Ordered Test)

      打开顺序测试文件,会显示如上图,左侧是项目中已经存在的测试方法,而右侧则是编辑的测试顺序。而一个测试方法可以在右侧的顺序中多次出现。
      也可以通过左下方的复选框来选择测试失败后是否继续执行后面的测试。
    4. 执行测试

      执行测试的话,可以在打开Test View(测试视图),选中刚刚新增的顺序测试,执行就可以了
    5. 测试结果


      顺序测试在TestResult(测试结果)结果中显示为一条记录,可以双击该记录,查看详细信息,如下图:

      在这里,我们刚刚所建的顺序测试的执行情况就一目了然了。

      关于顺序测试的内容就介绍这些了,更多内容还是需要大家来一起发掘。
    http://bigman.pw
  • 相关阅读:
    阿里云OSS进行文件下载时,报NOSuchKeys: com.aliyun.oss.OSSException: The specified key does not exist.
    [JAVA异常]ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2 JDWP exit erro
    mybatis 中的<![CDATA[ ]]>
    HttpClients.custom的创建
    RestTemplate可以自定义重试次数
    RegxUtils正则表达式工具类
    MYSQL中 != 和 is not的区别
    ccna ccnp ccie 区别
    【IDEA】IDEA SpringBoot访问不到webapp下的内容
    日志 | logback | logback-spring.xml
  • 原文地址:https://www.cnblogs.com/renzhiwei/p/3341145.html
Copyright © 2011-2022 走看看