Skip to content

segg3r/testng.util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

testng.util

Provides useful integrations with Mockito and Spring for TestNG test runner. Feel free to include it into your project using JitPack.

SpringContextListener

Allows you quickly build and run the test against application context, filled either with real objects, or mocks and spies instead. Consider having following class composition:

class Service {
  @Autowired
  MockedService mockedService;
  @Autowired
  SpiedService spiedService;
  @Autowired
  RealService realService;
}

Then it can be tested, using following testNG test suite:

@Listeners(SpringContextListener.class)
class ServiceTest {
  @Real
  Service service;
  @Real @Qualifier("someQualifier")
  RealService realService;
  @Spied
  SpiedService spiedService;
  ...
}

It also supports defining required Application context using @Configuration classes.

@Listeners(SpringContextListener.class)
@ContextConfiguration(configClasses = SomeSpringConfigurationClass.class)
...

Tests can be organized using hierarchy of classes and interfaces (e.g. your test suite can implement interface or extend class with @ContextConfiguration annotation).

##MongoStartupListener Allows to test your Mongo repositories against embedded Mongo instance.

@Listeners({SpringContextListener.class, MongoStartupListener.class})
class Service {
  @Autowired
  MongoTemplate template;
}