我正在进行一些集成测试,并且需要在测试之间清理数据库,以便我可以进行正确的断言,并且测试不会导致像Failed while seeding database
或Unable to clean database.
这样的错误。使用Arquillian进行Java集成测试,数据库清理
POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.2.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.2.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-api</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.extension</groupId>
<artifactId>arquillian-persistence-impl</artifactId>
<version>1.0.0.Alpha5</version>
<scope>test</scope>
</dependency>
一些测试类:
@RunWith(Arquillian.class)
@UsingDataSet("datasets/empty.yml")
public class SomeServiceCase {
@EJB
SomeService someService;
@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class)
.addPackages(true, "vo")
.addPackages(true, "service")
.addPackages(true, "domain")
.addAsManifestResource("test-persistence.xml", ArchivePaths.create("persistence.xml"));
}
@Test
@UsingDataSet("datasets/someModel/someModels.yml")
@Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.STRICT)
public void teastSomething() {
//modifies database content here
}
@Test
@UsingDataSet("datasets/someModel/someModels.yml")
@Cleanup(phase = TestExecutionPhase.AFTER, strategy = CleanupStrategy.STRICT)
public void testSomethingElse() {
//needs initial database content for tests to work
}
严格清理策略应该清除数据库,但它失败,因为外国键。所以,我想通过添加属性arquillian.xml
<property name="initStatement">SET REFERENTIAL_INTEGRITY FALSE</property>
我怎样才能达到我想要禁用Referential Integrity
?有任何想法吗?