长春企业网站哪里做的好,沈阳网站设计定制网站建设,网站建设培训赚钱吗,电商平台建站#01 JUnit简介
1.在项目工程中的Library,add 一个JUnit的Jar包#xff0c;按需要添加JUnit 3 或 JUnit 4#xff08;分为被测试类与测试类较佳#xff09;。
2.单元测试是由程序员完成的。
3.Java 5 之前的版本只能 用JUnit 4前的版本#xff08;因为JUnit 4用到Java 5的…#01 JUnit简介
1.在项目工程中的Library,add 一个JUnit的Jar包按需要添加JUnit 3 或 JUnit 4分为被测试类与测试类较佳。
2.单元测试是由程序员完成的。
3.Java 5 之前的版本只能 用JUnit 4前的版本因为JUnit 4用到Java 5的新特性----Annotation注解。
4.JUnit 4只是工具。
#02 setUp()tearDown()及相关断言方法。
1.JUnit3 利用反射JUnit4利用了注解。
2.JUnit3中setUp()初始方法而tearDown()销毁方法而JUnit4利用Before和After来类似的功能。
3.JUnit3中的测试方法必须是以test开头。
4.单元测试是由程序员编写的测试被测试代码的某一个很小的、特定的功能区域的代码。它可以用来确保在代码或者程序运行的环境中发生变化后已经存在的功能还是能够执行的。
5.JUnit3中每一个类都继承了一个叫做TestCase的类而TestCase的父类是Assert类;JUnit 4每一个可以不继承任何的类但是仍然可以直接使用import static org.junit.assert.*;在JUnit3中所有的测试类必须都是TestCase的子类;JUnit4中测试类可以是一个普通类也可以去继承一个类或者实现一个接口;要实现测试只需要在要测试的方法之前加Test 注释。
6.相关断言方法 assertSame()与assertEquals()并不完全相同same 相同equals相等
#03 AfterClass 与BeforeClass用法
1.AfterClassBeforeClass与After,Before,跟Java中的 静态块 和 非静态块 功能相类似。
2.AfterClass,BeforeClass用例数据库的连接只用于一次。
#04 Ignore,Test(expected ***.class),Test(timeout ^[1-9][0-9]*(millisecond)) #05 JUnit中的Failure,Error与Java 中的Exception,Error 的区别 JUnit中
Failure指的是由于预期的结果与实际运行的测试的结果不同而导致的實際運行單元的結果不同所導致例如当使用assertEquals()或其它assertXXX()方法断言失败时就会报出Failure如果发现Faulure你就要去检查你的测试方法或者是被测试方法中编写的逻辑是否有误。
Error指的是编写程序时没有考虑到的问题。在执行测试的断言之前程序就因为某种类型的意外而停止比喻说我们在操作数组的时候因为存取超出索引会引发ArrayIndexOutOfBoundsException这个时候程序就会报出Error程序将无法运行下去提前结束这个时候你要检查被测试方法中是不是有欠缺考虑到地方。
Java中
Exception: The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch.
The class Exception and any subclasses that are not also subclasses of RuntimeException are checked exceptions. Checked exceptions need to be declared in a method or constructors throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary.
Error: An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a normal condition, is also a subclass of Error because most applications should not try to catch it.
A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur. That is, Error and its subclasses are regarded as unchecked exceptions for the purposes of compile-time checking of exceptions.