java - Need to use dependency injection in unit tests - should I use junit or testng? -


we looking @ how use dependency injection unit tests (using jsr-330 syntax without explicitly specifying engine in basic tests if matters), , have used junit 4 far , been pleased it, appears not designed dependency injection in tests.

question is, whether junit suited tests run in dependency injection context, or if should switch testng?

just clarify: trying di-engine agnostic, , looking @ dagger.

i appreciate if opinions backed fact, thanks.

assuming using spring framework

you can annotate junit test classes this:

@runwith( springjunit4classrunner.class )   @contextconfiguration( "classpath:apptest-context.xml" ) public class appservicetest{    ...    ... } 

and inside apptest-context.xml have regular spring config stuff injecting dependencies.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -