I am learning Test Driven Development with JUnit5. In my reader this is written: " Annotations are added above a method to specify its behavior. A common scenario we find ourselves in is that we have to create a new object for each test. Instead of doing this in each test method, we can create a new method called setUp() for example, and add the @beforeEach annotation. This will make sure that this method is executed before each test method." But I don't know how can I use an object from a method in another method. Any help, please? This is my code:
@BeforeEach
public void setUp(){
IntSet set = new IntSet(4);
}
@Test
public void testIntSet(){
assertEquals(set.getCapacity(), 4); //error here: Cannot resolve symbol 'set'
}
Aucun commentaire:
Enregistrer un commentaire