我在maven项目中有这样的依赖关系。并将OpenEJB用于测试EJB bean
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-junit</artifactId>
<version>${openejb-junit.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
</exclusion>
</exclusions>
</dependency>
我对IReportService的测试
@RunWith(EJBContainerRunner.class)
public class ReportFacadeBeanTest {
@EJB
private IReportService iReportService;
@Test
public void testPrintReport() throws Exception {
Asserts.assertNotNull(iReportService);
}
}
当我尝试运行测试时,我有错误
java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JRDataSource
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetPublicMethods(Class.java:2902)
at java.lang.Class.getMethods(Class.java:1615)
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.processApplicationExceptions(AnnotationDeployer.java:2873)
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2383)
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1819)
at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:360)
at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:403)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:971)
at org.apache.openejb.OpenEjbContainer$Provider.createEJBContainer(OpenEjbContainer.java:364)
at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:77)
at org.apache.openejb.junit.jee.statement.StartingStatement.before(StartingStatement.java:96)
at org.apache.openejb.junit.jee.statement.DecoratingStatement.evaluate(DecoratingStatement.java:30)
at org.apache.openejb.junit.jee.statement.DecoratingStatement.evaluate(DecoratingStatement.java:32)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JRDataSource
at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:176)
at org.apache.openejb.core.TempClassLoader.loadClass(TempClassLoader.java:80)
... 21 more
当我改变范围时,所有工作都很好=(
如何使用范围运行测试?我没有&#39;想用use compile
答案 0 :(得分:0)
嗯......如果net.sf.jasperreports
在您的应用程序运行的任何地方都不可用,那么您必须
这当然取决于技术,因为每种技术都是将库添加到运行时环境中的方法。