I have a method in a a Junit test class, which tests if an email has been changed successfully, the problem is that it is returning an error message saying "void type not allowed" and I am not sure why.
Here is the method, which tests if an email has changed successfully but returns the mentioned error.
@Test
public void testChangeEmail()
{
assertEquals("001", teacher.getEmail());
assertEquals("002", teacher.changeEmail("002"));
assertEquals("002", teacher.getEmail());
}
and here is the whole class,
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TeacherTest
{
private Teacher teacher;
/**
* Default constructor for test class TeacherTest
*/
public TeacherTest()
{
}
/**
* Sets up the test fixture.
*
* Called before every test case method.
*/
@Before
public void setUp()
{
teacher = new Teacher("Amy Blunt", "001", "MNHA");
}
/**
* Tears down the test fixture.
*
* Called after every test case method.
*/
@After
public void tearDown()
{
}
@Test
public void testGetName()
{
assertEquals("Amy Blunt", teacher.getName());
}
@Test
public void testMembership()
{
assertEquals("001", teacher.getEmail());
}
@Test
public void testQualifications()
{
assertEquals("MNHA", teacher.getQualifications());
}
@Test
public void testChangeEmail()
{
assertEquals("001", teacher.getEmail());
assertEquals("002", teacher.changeEmail("002"));
assertEquals("002", teacher.getEmail());
}
}
I'm guessing your teacher.changeEmail();
method doesn't actually return anything.
Instead of assertEquals("002", teacher.changeEmail("002"));
just call teacher.changeEmail("002");
. The next assert checks to make sure the email was properly updated.
@Test
public void testChangeEmail()
{
assertEquals("001", teacher.getEmail());
teacher.changeEmail("002")
assertEquals("002", teacher.getEmail());
}