I am new to JUnit. I just started working on JUnit and i am getting following error.
The method assertEquals(String, String) is undefined for the type TestJunit
and my Javacode:
import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
public class TestJunit {
String message = "Hello World";
MessageUtil messageutil = new MessageUtil(message);
public void testPrintMessage()
{
assertEquals(message,messageutil.printMessage());
}
}
please help me resolve this issue.
You imported
import static org.junit.Assert.assertArrayEquals;
but not
import static org.junit.Assert.assertEquals;
You could also import every static member of Assert
with
import static org.junit.Assert.*;
Without these, Java thinks you are calling the method assertEquals
defined in the class the code is declared in. Such a method does not exist.
如果导入不起作用,请在运行代码之前尝试保存
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.