Powermock不断为ScriptEngineManager抛出错误

时间:2017-06-09 11:51:35

标签: java junit powermock easymock

由于我想在我的测试中使用来自JUnit的类别,我不得不用PowerMock重写一些模拟测试(在EasyMock之上使用powermock来模拟静态)。从RunWith(PowermockRunner.class)到下面;

    @Category(ServerTests.class)
@PrepareForTest(EnvironmentConfig.class)
@PowerMockIgnore( {"javax.management.*", "org.w3c.dom.*", "org.apache.log4j.*", "org.xml.sax.*",   "javax.xml.*"})
public class JmsHelperTest {

    @Rule
    public PowerMockRule rule = new PowerMockRule();

}

不幸的是我已经用PowerMockIgnore抑制了一些错误,但最后我无法抑制,我希望你能帮忙。

错误:

  

ScriptEngineManager providers.next():   javax.script.ScriptEngineFactory:Provider   jdk.nashorn.api.scripting.NashornScriptEngineFactory不是子类型   ScriptEngineManager providers.next():   javax.script.ScriptEngineFactory:Provider   jdk.nashorn.api.scripting.NashornScriptEngineFactory不是子类型   2017-06-09 13:37:24,660主要错误没有找到用于语言的ScriptEngine   JavaScript的。可用语言为:2017-06-09 13:37:24,776 main   警告没有找到名为{}的脚本

用于参考已加载的包;

import mypackage.EnvironmentConfig;
import mypackage.category.ServerTests;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;

import static org.easymock.EasyMock.expect;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import static org.powermock.api.easymock.PowerMock.mockStatic;
import static org.powermock.api.easymock.PowerMock.replay;

1 个答案:

答案 0 :(得分:6)

哦,我觉得自己很傻。 我专注于jdk.nashorn,但是当我向PowerMockIgnore添加javax.script。*时,它解决了错误。