powermockito

    1熱度

    2回答

    在我的代碼,我有一個for循環一樣, for(final Entry<Object, Object> entry : fileTypeProperties.entrySet()) { saveFileTypeToCompany(registeredCompany, entry.getKey().toString(), entry.getValue().toSt

    0熱度

    1回答

    我有一組單元測試,將存儲的XML文件解組到JAXB對象中。他們在工作。這些測試使用PowerMock(1.6.6),因爲CUT中的一個細節(測試代碼)需要「whenNew」子句。 我決定對一個對象工廠進行抽象,讓我轉向純Mockito。 當我這樣做時,在測試過程中,當將XML文件解組爲JAXB對象時,我開始出現無法解釋的問題。它根本不存儲某些元素到JAXB對象中。 ,做解組的方法是這樣的: pro

    1熱度

    1回答

    我嘲笑以下方法: public static void cleanAndCreateDirectories(@NonNull final Path path) throws IOException { // If download directory exists(should not be symlinks, clear the contents. System.out.

    2熱度

    2回答

    如何在爲靜態方法編寫junit時從靜態方法調用實例方法調用?我正在爲現有代碼編寫測試。 class A { public static D methodX() { B b = new B(); C c = b.doSomething(); } } class B { public C doSomething() {

    1熱度

    2回答

    我試圖測試我的Utils類。其中一些方法使用其他類方法。我想嘲笑內部方法的使用,所以測試會假設它們工作(爲了使它成爲真正的單元測試,它測試了具體的方法)。 我想測試 'buildUrl' 的方法: public static String buildUrl(String path, List<Pair> queryParams, DateFormat dateFormat) { fina

    0熱度

    1回答

    的新對象,我需要模擬創建兩個對象 Holder<MyClass1> h1 = new Holder<>(); Holder<MyClass2> h2 = new Holder<>(); 我使用的Mockito和PowerMock Holder<MyClass1> mock1 = PowerMockito.spy(new Holder<MyClass1>()); Holder<MyClass

    0熱度

    1回答

    我正在使用TestNG來進行單元測試並模擬我的應用程序。 我的問題是,當我用PowerMockito.whenNew(ClassB.class)的方法和調試ClassA時,我發現objB是原來沒有嘲弄的。 經過多次調查,我用 import org.junit.Test; 代替 進口org.testng.annotations.Test; 並嘗試使用Junit測試代替TestNG。 令人驚訝的是,它

    1熱度

    1回答

    請幫我模擬下面的代碼。無法模擬調用JdbcTemplate對象的getDataSource()。 @Override public List<AttributeThresholdRange> getThresholdsRangeForXHS(QueryThresholdsRequest queryThresholdsRequest) { ArrayOfString attribute

    0熱度

    1回答

    我想模擬一個返回類型爲void的私有字段的方法。在我的測試中,我試圖模擬aClass.doSomething()以拋出IllegalStateException,我需要驗證是否調用了recover()。下面是一個例子: public class ClassToTest implements Runnable { private ClassToMock aClass; @Ove

    1熱度

    2回答

    class Continents{ Map<String,String> COUNTRY_CURRENCY_MAP = Singleton.getInstance().getCountryCurrencyMap() } 我想模擬使用電源mockito的單身人士班,但我無法做到這一點。 Continents continents = mock(Continents.class);