when use junit4 + powermock to execute all test suites , I got an error : swt-win32-3650.dll already loaded in another classloader

强颜欢笑 提交于 2019-12-22 08:12:04

问题


when use junit4 + powermock to execute all test suites , I got an error : swt-win32-3650.dll already loaded in another classloader alltest.java:

@RunWith( Suite.class )
@SuiteClasses( {test1.class, test2.class} )
public class AllTests
{
}

test1.java

@RunWith( PowerMockRunner.class )
@PrepareOnlyThisForTest( {Object.class} )
public class test1 extends TestCase
{
    @Test
    public void testcase()
    {
        Shell sh = Mockito.mock( Shell.class );
        PowerMockito.when( sh.getText() )
                .thenReturn( this.getClass().getName() );
        PowerMockito.when( sh.getText() )
                .thenReturn( this.getClass().getName() );
        assertTrue( sh.getText() == this.getClass().getName() );
    }

}

test2.java

@RunWith( PowerMockRunner.class )
@PrepareOnlyThisForTest( {Object.class} )
public class test2 extends TestCase
{
    @Test
    public void testcase()
    {
        Shell sh = Mockito.mock( Shell.class );
        PowerMockito.when( sh.getText() )
                .thenReturn( this.getClass().getName() );
        assertTrue( sh.getText() == this.getClass().getName() );
    }
}

回答1:


Use PowerMockIgnore to defer loading of conflicting classes twice. The dll swt-win32-3650.dll that you have mentioned would have been probably already loaded. So check for classes which can do this and put them in PowerMockIgnore arguements'.



来源:https://stackoverflow.com/questions/16832078/when-use-junit4-powermock-to-execute-all-test-suites-i-got-an-error-swt-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!