Java 未定义 TestJunit 类型的 assertEquals(String, String) 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22676040/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The method assertEquals(String, String) is undefined for the type TestJunit
提问by SOF User
I am new to JUnit. I just started working on JUnit and i am getting following error.
我是 JUnit 的新手。我刚开始在 JUnit 上工作,但出现以下错误。
The method assertEquals(String, String) is undefined for the type TestJunit
未定义 TestJunit 类型的 assertEquals(String, String) 方法
and my Javacode:
和我的 Java 代码:
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.
请帮我解决这个问题。
采纳答案by Sotirios Delimanolis
You imported
您导入的
import static org.junit.Assert.assertArrayEquals;
but not
但不是
import static org.junit.Assert.assertEquals;
You could also import every static member of Assertwith
您还可以导入Assertwith 的每个静态成员
import static org.junit.Assert.*;
Without these, Java thinks you are calling the method assertEqualsdefined in the class the code is declared in. Such a method does not exist.
没有这些,Java 认为您正在调用在assertEquals声明代码的类中定义的方法。这样的方法不存在。

