Suppress static block

时间:2017-06-15 09:36:19

标签: java junit integration-testing powermockito

Programming Language : Java
Testing tool : powermockito,Junit

I have a static block in my code. I am using that code particle as several reference. While during integration testing (using powermockito) I mocked a getWebDetails() method in the below example. The method for mocking (getWebDetails) is also getting called from the static block in my program, so it excecutes before my test gets excecuted and returns a null value. I need to assign values to xml contents during my testing.

class test1{
    private static String xmlcontents;

    static {
        xmlcontents= ServiceUtils.getWebDetails();
    }

    public static String getWebDetails() throws Exception{
        url = test2.getURL();
        return url;
    }
}

Nota bene (please note): I tried using @SuppressStaticInitializationFor("test1"), but it suppresses all the static methods inside the class.

Can anyone help me? Any help will be highly appreciable..

0 个答案:

没有答案