当使用junit4 + powermock来执行所有测试套件时,我遇到了一个错误:swt-win32-3650.dll已经在另一个类加载器中加载。

4
当使用Junit4 + PowerMock执行所有测试套件时,我遇到了一个错误:swt-win32-3650.dll已经在另一个类加载器中加载。 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个回答

1
使用PowerMockIgnore推迟加载冲突类两次。你提到的 dll swt-win32-3650.dll 可能已经被加载。因此,请检查可以做到这一点的类,并将它们放入 PowerMockIgnore 参数中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接