Does Junit reinitialize the class with each test method invocation?

前端 未结 5 1957
执笔经年
执笔经年 2020-12-10 11:05

When i run the below code, both test cases come true:

import static junit.framework.Assert.assertEquals;

import org.junit.Test;

public class MyTest{
    pr         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-10 11:44

    Look at the documentation of org.junit.runner.Runner:

    The default runner implementation guarantees that the instances of the test case class will be constructed immediately before running the test and that the runner will retain no reference to the test case instances, generally making them available for garbage collection.

    Unit tests should be independant otherwise it becomes unmaintable. Note that the order of executed methods is not guaranteed (unless you use the annotation @FixMethodOrder).

提交回复
热议问题