我有一个TestRunner类,它运行来自jUnit AllTests(TestSuite)的所有测试,其中包含我的应用程序所需的所有测试(UTests.java)......
replaceCurrentItemWithPlayerItem
StudentBean.java
public class TestRunner {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(AllTests.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
@RunWith(Suite.class)
@SuiteClasses({ UTests.class })
public class AllTests {
}
@Test public void testAddStudent() {
StudentBean sb = new StudentBean();
Student s1 = new Student(4, "Ognjen", "Car");
System.out.println(s1.toString());
Boolean s = sb.addStudent(s1);
System.out.println(s1);
assert (s == true);
// fail("Not yet implemented");
}
一旦我运行TestRunner类,就会出现2个错误,它们似乎是一个....
1st在控制台:
@PersistenceContext
EntityManager em;
@Override
public Boolean addStudent(Student s) {
try{
Student s1 = new Student(10,"asd", "asd"); //for testing...later I ll delete it
em.persist(s);
em.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
return true;
}
假
2nd在JUnit控制台:
test.UTests: DeploymentScenario contains a target (_DEFAULT_) not matching any defined Container in the registry.
Please include at least 1 Deployable Container on your Classpath.
错误是要求将Deployable容器添加到我的类路径中,我不知道该怎么做...
你能帮助我吗?
答案 0 :(得分:2)
你必须在你的pom中添加一些依赖项。它看起来像那样:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>2.3.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
答案 1 :(得分:0)
添加以下依赖项:
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-7.0</artifactId>
<version>1.0.3.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
<version>1.0.0.CR9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-core</artifactId>
<version>2.3.5.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
</dependencies>
然后右键单击该项目,转到属性,然后在活动maven配置文件下单击maven,粘贴此“ arquillian-weld-ee-embedded”。 如果您要使用其他着色剂,请在Maven活动配置文件中使用它。