zoukankan      html  css  js  c++  java
  • JUnit3 和 JUnit4的区别

    JUnit3 和 JUnit4的区别

    1、JUnit 4使用org.junit.*包而JUnit 3.8使用的是junit.Framework.*;为了向后兼容,JUnit4发行版中加入了这两种包。

    2、JUnit3中,测试类需要继承junit.framework.TestCase类,而在JUniy4则不用。

    3、JUnit3通过分析方法名称来识别测试方法:方法名必须以“test”为前缀,它必须返回void,而且它必须没有任何参数(例如 public void testDivide())。不遵循这个命名约定的测试方法将被JUnit框架忽略,而且不抛出任何异常(指示发生了一个错误)。

    在JUnit4中,测试方法不必以'test'为前缀,而是使用@Test注解。但测试方法也必须返回void并且无参。在JUnit4中,可以在运行时控制这个要求,并且不符合要求的话会抛出一个异常:

    java.lang.Exception: Method xxx should have no parameters
    java.lang.Exception: Method xxx should be void

    @Test注解支持可选参数。它声明一个测试方法应该抛出一个异常。如果它不抛出或者如果它抛出一个与事先声明的不同的异常,那么该测试失败。

  • 相关阅读:
    concrete maths ch4 number theory
    Aho-Corasick algorithm
    Finding repetitions
    Suffix Automaton
    Z-function and its calculation
    mongodb安装与启动
    centos redis 集群搭建
    nginx实现热部署(平滑升级)
    nacos集群部署安装
    springboot+zookeeper+dubbo整合
  • 原文地址:https://www.cnblogs.com/sddychj/p/7521589.html
Copyright © 2011-2022 走看看