when use junit4 + powermock to execute all test su

2019-05-06 16:13发布

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条回答
狗以群分
2楼-- · 2019-05-06 16:45

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'.

查看更多
登录 后发表回答