2
我需要模擬一個類的靜態方法,並在我的測試中使用該模擬方法。現在看來,我只能使用PowerMock來做到這一點。PowerMockRunner不適用JUnit ClassRules
我使用相應的類爲@RunWith(PowerMockRunner.class)和@PrepareForTest註解類。
在我的測試中,我有一個@ClassRule,但是在運行測試時,規則沒有正確應用。
我該怎麼辦?
RunWith(PowerMockRunner.class)
@PowerMockIgnore({
"javax.xml.*",
"org.xml.*",
"org.w3c.*",
"javax.management.*"
})
@PrepareForTest(Request.class)
public class RoleTest {
@ClassRule
public static HibernateSessionRule sessionRule = new HibernateSessionRule(); // this Rule doesnt applied
只用於追蹤:https://github.com/powermock/powermock/issues/687。 PowerMock基本上打破了JUnit測試處理,並沒有真正的解決方案。 –