`

Use JUnit (2)

    博客分类:
  • Java
阅读更多

 

Junit3 diff Junit4

 

  • 包命名从junit.framework.xxx变更到org.junit.xxx. 
  • 在JUnit3.8中测试类必须继承TestCase父类,JUnit4中测试类不用继承TestCase 
  • 在JUnit3.8中 测试方法满足如下原则1)public 2)void 3)无方法参数4)方法名称必须以test开头,JUnit测试方法不用满足4)即命名不用test +methodName ,用Annotation。

 


Junit命令行下使用
note: Test definition head
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Test 

 
1) use @Test
import org.junit.Test; 
public class ExpressionPuzzlers {

	@Test
	public void dosEquis() {
		char x = 'X';
		int i = 0;

		System.out.println(true ? x : 0);
		System.out.println(false ? i : x);
	}
}
 

2) 添加CLASSPATH,如CLASSPATH=".;D:\junit4.10\junit-4.10.jar"
javac ExpressionPuzzlers.java
or
不设置CLASSPATH,javac -classpath D:\junit4.10\junit-4.10.jar ExpressionPuzzlers.java

3) run
java org.junit.runner.JUnitCore ExpressionPuzzlers
直接运行 java ExpressionPuzzlers 会提示没有main方法
note:run in program with "org.junit.runner.JUnitCore.runClasses(TestClass.class, ...);"
原理分析:
在JUnitCore中有相应的main方法,通过读入参数运行被测试类
main method in JunitCore.java
public static void main(String... args) {
		runMainAndExit(new RealSystem(), args);
	}
 


 

分享到:
评论

相关推荐

    How to use the Junit in JDeveloper

    NULL 博文链接:https://hidefromall.iteye.com/blog/259132

    Pragmatic Unit Testing in Java 8 with JUnit(PACKT,2015)

    Once past the basics, you'll learn why you want to write unit tests and how to effectively use JUnit. But the meaty part of the book is its collected unit testing wisdom from people who've been there,...

    Packt Publishing Mastering Unit Testing Using Mockito and JUnit (2014)

    You will begin with how to use advanced JUnit 4 features, improve code coverage, automate JUnit tests, monitor code quality, write JUnit tests for the database and web tier refactor legacy code, mock...

    junit官方jar包

    Unit是由 Erich Gamma 和 ...Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How)完成功能和完成什么样(What)的功能。Junit是一套框架,继承TestCase类,就可以用Junit进行自动测试了。

    Testing.with.Junit.1782166602

    Chapter 2: Writing Well-structured Tests Chapter 3: Developing Independently Testable Units Chapter 4: Testing Exceptional Flow Chapter 5: Using Runners for Particular Testing Purposes Chapter 6: ...

    junit4.12 hamcrest-core-1.3

    在使用junit4.12时,同时需要hamcrest-core-1.3 http://junit.org/junit4/ junit.jar: Includes the Hamcrest classes. The simple all-in-one solution to get ... Lets you use a different Hamcrest version.

    JUnit Howto.pdf

    The tutorials that I used to learn JUnit spent about 80% of my time learning the program that was to be tested as an example, and the ...have an hour to learn to use a terrific product, then proceed.

    java-junit4.11

    EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND ...WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    Use Case Driven Object Modeling with UML_ Theory and Practice.pdf

    Do an Initial Domain Model Before You Write the Use Cases. . . . . . 50 Driving Your Design (and Your Tests) from the Use Cases. . . . . . . . . 51 Use Case Modeling in Theory. . . . . . . . . . . . ....

    JUnit4和Guice测试库Acai.zip

     // Use the injected value of foo here  }  private static class MyTestModule extends AbstractModule {  @Override protected void configure() {  bind(MyClass.class).to...

    Agile.Android.1484297008

    When to use Espresso and when to use JUnit What is mock testing and how to use Mockito in your Android apps What are and how to use third party tools like Hamcrest, Roblectric, Jenkins and more How to...

    openhie-integration-tests:OpenHIE 集成测试作为 JUnit 代码

    openhie-集成-测试OpenHIE 集成测试作为 JUnit 代码配置单元 Tets 单元测试被配置为一系列参数到 JUnit 主机(例如 eclipse 或 Bamboo),它们如下: ohie-cr-endpoint = ipaddress:port = of the client registry ...

    Java开源,用于画图 pdf

    It's part of JUnit, the tool we use for unit testing out code. See http://junit.org Q. How do I add two parallel edges to a SparseGraph? A. Make sure the graph allows parallel edges (this means ...

    Guice教程(Google)

    You can also use typical Java project tools such as JUnit and Ant when creating GWT applications. The GWT is a free download, and you can freely distribute the client- and server-side code you create ...

    Mockito Cookbook - Packt

    Mockito is a testing framework that allows you to easily create test doubles (mocks) ... This book shows the use of Mockito's popular unit testing frameworks such as JUnit, PowerMock, TestNG, and so on.

    thymeleaf-tests-3.0-spring5.zip

    Tests under the org.thymeleaf.engine package are designed for use with the thymeleaf-testing library. All tests and are launched using JUnit. The JUnit test classes are contained at several folders, ...

    基于Java+Mssql的学校教务管理系统源码

    本系统运用J2EE中的JSP MODEL2的MVC (MODEL+VIEW+CONTROL)模型,运用Eclipse3.1.8 + Tomcat5.0 + JDK5.0 + MSSQL 的组合开发平台开发测试。...Abstract:This System use JSP MODEL2 MVC (MODEL+VIEW+CONTROL) of J2

    swingx包

    You can use our Ant build scripts or use your own--some IDEs make this easy to do. <br>To compile from the command line, you'll need to have Apache Ant installed; see ...

    Android代码-strikt

    Strikt is an assertion library for Kotlin intended for use with a test runner such as JUnit or Spek. Strikt is under development, but 100% usable. The API may change until a version 1.0 is released. ...

Global site tag (gtag.js) - Google Analytics