Java – JUnit: call @ after to set the object to null

Suppose I have the following simple JUnit test

private Person person;

@Before
public void createObject()
{
   String firstName = "John";
   String lastName = "Doe";

   person = new Person(firstName,lastName);
}

@Test
public void test1()
{
   assert(firstName.equals("John"));
}

@Test
public void test2()
{
   assert(lastName.equals("Doe"));
}

Should I have a @ after method that sets person = null?

I tried a similar test without @ after method, and I can't seem to find out whether it has any advantages or disadvantages

It doesn't make sense to ignore test names I just released a simple example

Solution

You can, but it doesn't make any sense Call the @Before method before each test run. With or without @ after, people will be GC

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>