Why does Spring autoload stop working when I add the RunWith annotation?

After adding annotation RunWith, that is, @RunWith(PowerMockRunner.class)Autwire Spring no longer works!

class B {  
  @Autowire  
  SessionFactory session;
}

@RunWith(PowerMockRunner.class)  
@PrepareForTest{SomeClass.class}

class Testing {  

  @Test
  methodA(){  
    //mehod 
  }

  @Test
  methodD(){  
  }    
}  

Now method A calls a call to class B, but due to annotation RunWith(PowerMockRunner), the Autowiring function does not work. Any help would be greatly appreciated!

+5
source share
2 answers

In 2016, you can use the runner delegate with PowerMockito, effectively using two members:

@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(SpringJUnit4ClassRunner.class)

More details here: https://github.com/jayway/powermock/wiki/JUnit_Delegating_Runner

+7
source

Spring ( ). , spring beans. , @RunWith(SpringJUnit4ClassRunner.class). , JUnit , PowerMockRunner.

+1

All Articles