I have a Spring based application and am in the process of unit testing. I use TestNG for unit tests. For my test, I need to use PowerMockito to make fun of some static methods. I also need to use the Spring test configuration file for my unit test only.
I cannot write my unit tests combining all three, i.e. TestNg, PowerMock and Spring.
I can combine TestNG and Spring by extending the AbstractTestNGSpringContextTests class, but, be that as it may, mocks the static methods, instead it executes the actual static method. Something like below:
@PrepareForTest(MyUtils.class) @ContextConfiguration(locations = { "classpath:config/test-context.xml"}) public class MyImplTest extends AbstractTestNGSpringContextTests{ ..... }
I can combine TestNG with PowerMockito by extending the PowerMockTestCase class. But then the Spring test configuration files are not allowed. Something like below:
@PrepareForTest(MyUtils.class) @ContextConfiguration(locations = { "classpath:config/test-context.xml"}) public class MyImplTest extends PowerMockTestCase{ ..... }
Is there a way to write my unit tests combining all three, i.e. TestNg, PowerMockito and Spring context?
source share