当使用junit4 powermock执行所有测试套件时,我收到一个错误:swt-win32-3650.dll已经加载到另一个类加载器中 alltest. java: @RunWith( Suite.class )@SuiteClasses( {test1.class, test2.class} )public class AllTests{
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() ); } }使用 PowerMockIgnore延迟加载冲突类两次.您提到的dll swt-win32-3650.dll可能已经加载了.因此,检查可以执行此操作的类并将它们放入PowerMockIgnore争论中.