lundi 25 mai 2020

JUnit makes a new instance of the class without @BeforeEach?

In order to refactor testing, we are taught that JUnit will make a new instance of the class every time by doing the following:

public class someClassTest{

  final private someClass obj1 = new someClass();

  @Test
  public void t1() {
      Assertions.assertEquals(1, obj1.returnOne());
  }

  @Test
  public void t2() {
      Assertions.assertEquals(8, obj1.return(2));
  }
}

Rather than using something like

@BeforeEach
void setup(){
someClass obj1 = new someClass();}

or initializing it inside the test methods every time.

My question is, why and how does my first block of code work to achieve the same purpose as the @BeforeEach?

Aucun commentaire:

Enregistrer un commentaire