私のテストでは、春の依存性注入のトランザクションとパラメーターを使用する必要があります。パラメータ化された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 });
return parametry;
}
@Before
public void vytvorTurnaj() throws Exception {
testContextManager = new TestContextManager(getClass());
testContextManager.prepareTestInstance(this);
}
@Test
public void test1() {
Assert.assertFalse(false);
}
}
この例は機能します。次に、このクラスにトランザクションを追加する必要があります。
@RunWith(value = Parameterized.class)
@ContextConfiguration(locations = { "classpath:applicationContextTest-business.xml" })
@Transactional
@TransactionConfiguration(defaultRollback = true)
public class TournamentServiceTest ...
この2つの新しい行を追加すると、このテストは例外をスローしました:
org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.toursys.processor.service.TournamentServiceTest]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
彼は空のコンストラクターを追加したいので:
public TournamentServiceTest() {
this.playerCount = 20;
}
しかし、パラメータ化されたカントはこのテストを実行できないため、これを追加することはできません。どうすればこの問題を解決できますか?