Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java EasyMock缺少行为,即使它';定义_Java_Junit_Easymock - Fatal编程技术网

Java EasyMock缺少行为,即使它';定义

Java EasyMock缺少行为,即使它';定义,java,junit,easymock,Java,Junit,Easymock,无论我做什么,在尝试模拟方法时都会出现以下错误 java.lang.IllegalStateException:前面的方法调用缺少行为定义: ConfigurationSection.get(“国家语言”) 用法是:expect(a.foo()).andXXX() 我的测试代码: EasyMock.expect(section.getString("country-language")).andReturn("US"); LocaleManager.updateLocale(section,

无论我做什么,在尝试模拟方法时都会出现以下错误

java.lang.IllegalStateException:前面的方法调用缺少行为定义: ConfigurationSection.get(“国家语言”) 用法是:expect(a.foo()).andXXX()

我的测试代码:

EasyMock.expect(section.getString("country-language")).andReturn("US");

LocaleManager.updateLocale(section, Collections.emptyList());
EasyMock.expectLastCall();

replayAll();

Assert.assertEquals("Test", TranslatedMessage.translate("test"));
verifyAll();
expect andReturn是为模拟类调用的,静态upateLocale方法首先调用该方法。 奇怪的是,这个测试效果很好:

EasyMock.expect(section.getString("country-language")).andReturn("US");
replayAll();

Assert.assertEquals("US", section.getString("country-language"));
verifyAll();
但是从外部方法调用它不起作用。

您的模拟显示:

EasyMock.expect(section.getString("country-language"))
错误显示:

ConfigurationSection.get("country-language")
你不是在嘲笑
get(“国家语言”)
。你在模仿
getString(“国家语言”)


不相关,但
verify
是维护的噩梦,通常应避免。这将测试代码直接绑定到实现。如果可能的话,测试应该关注输入和输出。

我忘记了自己的实现,它一直在我的眼皮底下!谢谢你的帮助,我花了好几个小时试图让任何东西都能正常工作。我刚刚意识到我之前使用PowerMock时使用了相同的方法,我想我的代码默认值是正确的。必须将测试修复为非默认语言。