问题
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