Autowiring Spring services into JUnit tests
Add these two annotations to the test class AppTest, like in the following example:
@RunWith(SpringRunner.class )
@SpringBootTest
public class ProtocolTransactionServiceTest {
@Autowired
private ProtocolTransactionService protocolTransactionService;
}
@SpringBootTest
loads the whole context.
Add the following annotation to MyApplicationContext
for the service to be scanned @ComponentScan("myservice.package.name")