Tuesday, 15 May 2012

java - How to create spring parametrized transactional test -



java - How to create spring parametrized transactional test -

in tests need utilize spring dependency injection transactional , parameters. found illustration how utilize parametrized , di:

@runwith(value = parameterized.class) @contextconfiguration(locations = { "classpath:applicationcontexttest-business.xml" }) public class tournamentservicetest { @autowired tournamentservice tournamentservice; public tournamentservicetest(int playercount) { this.playercount = playercount; } @parameters public static list<object[]> data() { final list<object[]> parametry = new arraylist<object[]>(); parametry.add(new object[] { 19 }); parametry.add(new object[] { 20 }); homecoming parametry; } @before public void vytvorturnaj() throws exception { testcontextmanager = new testcontextmanager(getclass()); testcontextmanager.preparetestinstance(this); } @test public void test1() { assert.assertfalse(false); } }

this illustration works. need add together transaction class:

@runwith(value = parameterized.class) @contextconfiguration(locations = { "classpath:applicationcontexttest-business.xml" }) @transactional @transactionconfiguration(defaultrollback = true) public class tournamentservicetest ...

when add together 2 new line test thrown exception:

org.springframework.aop.framework.aopconfigexception: not generate cglib subclass of class [class org.toursys.processor.service.tournamentservicetest]: mutual causes of problem include using final class or non-visible class; nested exception java.lang.illegalargumentexception: superclass has no null constructors no arguments given

because want add together empty constructor:

public tournamentservicetest() { this.playercount = 20; }

but cant add together because parameterized cant run test. how can solve problem ?

the spring testcontext framework not back upwards parameterized tests. need custom rule or runner this. there open pull request, can take code there.

as of spring 4.2 can use

@classrule public static final springclassrule spring_class_rule = new springclassrule(); @rule public final springmethodrule springmethodrule = new springmethodrule();

java spring junit

No comments:

Post a Comment