Code Monkey home page Code Monkey logo

javatest-in-action's Introduction

1. Junit

1.1 @After和@Before

@Before用于在执行@Test注解的方法前,创建一些实例变量或者资源

@After用于在执行@Test注解的方法后,销毁实例变量或者资源

由于这两个注解是在执行每个@Test的方法时,都会调用,而且在执行前都会new xxxTest实例,也就是测试类,实例变量的状态不会传递给下一个测试方法。

1.2 @AfterClass和@BeforeClass

@BeforeClass标注的方法是静态的,方法内部放一些在所有测试方法执行之前都会公用的资源代码,比如数据库的连接,获取流,只会在所有测试方法调用前执行一次

@AfterClass用于标注的方法是静态的,方法内部放一些在所有测试方法执行之后都会释放的资源代码,比如数据库连接的释放,流的关闭,只会在所有测试方法调用完成后进行执行

1.3 Junit执行逻辑

invokeBeforeClass(xxxTest.class); // 执行xxxTest类的@BeforeClass静态方法
for(Method method:allTestMethods) {
    xxxTest test = new xxxTest();
    test.setUp(); // @Before
    test.invoke(method); // @Test
    test.tearDown(); // @After
}
invokeAfterClass(xxxTest.class); // 执行xxxTest类的@AfterClass静态方法

javatest-in-action's People

Contributors

yidou120 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.