I tried to follow the example offered in the answer to this very similar question, but it does not work for me. I get the following error message:
java.lang.
I got this working by extending the PowerMockTestCase class that handles this kind of thing for TestNG:
@PrepareForTest(TestEnumerable.class)
@Test(groups = {"LoadableBuilderTestGroup"})
public class LoadableBuilderTest extends PowerMockTestCase {
private TestEnumerable mockEnumerable;
@SuppressWarnings("unchecked")
@BeforeMethod
public void setUp() {
mockEnumerable = PowerMockito.mock(TestEnumerable.class);
}
}
You need to run this with PowerMockRunner
eg.
@RunWith(PowerMockRunner.class)
@PrepareForTest({ ExampleEnumerable.class})
@Test(groups = {"LoadableBuilderTestGroup"})
public class LoadableBuilderTest {
private ExampleEnumerable mockEnumerable;
@BeforeMethod
public void setUp() {
mockEnumerable = mock(ExampleEnumerable.class);
}
}
Hi guys, to me worked as below:
First add power mockito on pom.xml:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
and then on my class:
@RunWith(PowerMockRunner.class)
@PrepareForTest({EnumClass.class})
public class EnumClassTest{
private EnumClassTest enumClassTest;
@Before
public void setUp() {
enumClassTest = mock(EnumClassTest.class);
}
@Test
public void someMethod() {
//My code test here
}