我正在尝试为大型项目编写一个简单的arquillian测试。有一堆QClasses被自动创建以查询数据库,但似乎在Shrinkwrap.create()运行时,这些类尚未创建,部署永远不会完成。
MyTest课程:
package pkg.integration.service;
import static org.junit.Assert.assertNotNull;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.archive.importer.MavenImporter;
import org.junit.Test;
import org.junit.runner.RunWith;
import pkg.service.TestService;
@RunWith(Arquillian.class)
public class MyTest {
@Deployment
public static WebArchive getDeploy() {
return ShrinkWrap.create(MavenImporter.class)
.loadPomFromFile("/path/to/pom.xml")
.importBuildOutput()
.as(WebArchive.class);
}
@Inject
private TestService testService;
@Test
public void test() {
assertNotNull(testService);
}
}
执行堆栈跟踪:
java.lang.RuntimeException: Could not invoke deployment method: public static org.jboss.shrinkwrap.api.spec.WebArchive br.com.company.integration.service.MyTest.getDeploy()
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:181)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generateDeployment(AnnotationDeploymentScenarioGenerator.java:103)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.generate(AnnotationDeploymentScenarioGenerator.java:64)
at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
at org.jboss.arquillian.container.test.impl.client.ContainerEventController.execute(ContainerEventController.java:100)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:103)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:85)
at org.jboss.arquillian.test.impl.TestContextHandler.createClassContext(TestContextHandler.java:92)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.test.impl.TestContextHandler.createSuiteContext(TestContextHandler.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:96)
at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:92)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:143)
at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:114)
at org.jboss.arquillian.test.impl.EventTestRunnerAdaptor.beforeClass(EventTestRunnerAdaptor.java:87)
at org.jboss.arquillian.junit.Arquillian$2.evaluate(Arquillian.java:202)
at org.jboss.arquillian.junit.Arquillian.multiExecute(Arquillian.java:431)
at org.jboss.arquillian.junit.Arquillian.access$200(Arquillian.java:55)
at org.jboss.arquillian.junit.Arquillian$3.evaluate(Arquillian.java:219)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.jboss.arquillian.junit.Arquillian.run(Arquillian.java:167)
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:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator.invoke(AnnotationDeploymentScenarioGenerator.java:177)
... 49 more
[omitted]
symbol: class QConfiguracao
location: package com.company.portal.model, /path/to/src/main/java/pkg/portal/service/UserService.java:[124,38] cannot find symbol
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
[... A LOT of 'cannot find symbol' errors pointing to QClasses]
location: package pkg.vo
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.constructCompilationException(AbstractCompilingProcessor.java:120)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.AbstractCompilingProcessor.compile(AbstractCompilingProcessor.java:92)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:84)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.packaging.WarPackagingProcessor.importBuildOutput(WarPackagingProcessor.java:50)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:49)
at org.jboss.shrinkwrap.resolver.impl.maven.archive.importer.PomEquippedMavenImporterImpl.importBuildOutput(PomEquippedMavenImporterImpl.java:44)
at pkg.service.MyTest.getDeploy(MyTest.java:27)
... 54 more
Test ignored.
jun 16, 2017 8:32:38 PM org.jboss.arquillian.core.impl.ObserverImpl resolveArguments
ADVERTÊNCIA: Argument 2 for ArquillianServiceDeployer.undeploy is null. It won't be invoked.
Process finished with exit code 255
构建>:
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.sql</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources/db</directory>
<targetPath>db</targetPath>
<filtering>false</filtering>
</resource>
</resources>
<filters>
<filter>${basedir}/src/main/resources/filters/${filter.name}.properties</filter>
[filters...]
</filters>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<extensions>false</extensions>
</plugin>
<!-- Compila .jrxml para .jasper -->
<plugin>
<groupId>com.alexnederlof</groupId>
<artifactId>jasperreports-plugin</artifactId>
<dependencies>
<!--Força para ser as mesmas versões de runtime-->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>${jasperreports.version}</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>${jasperreports-fonts.version}</version>
</dependency>
</dependencies>
</plugin>
<!-- mvn backupdb:copy backupdb:restore -->
<plugin>
<groupId>com.company</groupId>
<artifactId>backupdb-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<databaseType>postgres</databaseType>
<bucketFolder>${company.db.name}/db</bucketFolder>
<databaseName>${company.db.name}</databaseName>
<postScript>src/test/resources/db/post_restore.sql</postScript>
</configuration>
</plugin>
<plugin>
<groupId>com.company</groupId>
<artifactId>company-jpa-maven-plugin</artifactId>
<version>${company.jpa.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<includes>
<include>**/*Spec.java</include> <!-- Yes, .java extension -->
<include>**/*Test.java</include> <!-- Just in case of having also "normal" JUnit tests -->
</includes>
<argLine>-Xmx256m</argLine>
<properties>
<property>
<name>listener</name>
<value>com.company.testng.ListenerDominio</value>
</property>
</properties>
<threadCount>1</threadCount>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>addTestSources</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.gmaven.runtime</groupId>
<artifactId>gmaven-runtime-2.0</artifactId>
<version>1.5</version>
<exclusions>
<exclusion>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<configuration>
<testSources>
<testSource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<versionRange>[1.0-beta-2,)</versionRange>
<goals>
<goal>compile-reports</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
<!-- we want to execute specifications -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<testSourceDirectory>${project.basedir}/src/test/groovy</testSourceDirectory>
<includes>
<include>**/*Specification*</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>arquillian-wildfly-remote</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- this is required to get test resources filtered properly -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
</plugin>
</plugins>
</pluginManagement>
</build>
dependencyManagement&GT;
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-bom</artifactId>
<version>${version.org.jboss.shrinkwrap.resolver}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-bom</artifactId>
<version>${version.org.jboss.shrinkwrap}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.org.jboss.arquillian}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-core</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-standalone</artifactId>
<version>${version.org.jboss.arquillian}</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.spock</groupId>
<artifactId>arquillian-spock-container</artifactId>
<version>1.0.0.Final</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-external-bom</artifactId>
<version>2.0.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>company-parent-test</artifactId>
<version>1.0.0</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.1.Final</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
所以...我缺少什么?
PS:我正在通过Intellij执行测试。终端上的mvn clean package
给了我一个:
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[8,33] error: package org.jboss.arquillian.junit does not exist
[ERROR] /path/to/src/test/java/company/service/MyTest.java:[16,9] error: cannot find symbol
答案 0 :(得分:1)
IIRC Maven亚军并不尊重所有插件,只是常见插件。我认为在你的情况下你应该使用EmbeddedMaven https://github.com/shrinkwrap/resolver#embedded-maven而不是导入器。
答案 1 :(得分:0)
是的,MavenImporter可能不是最适合你的解决方案 - 它需要你的依赖堆栈,编译src/main/java
目录中的所有类,获取所有资源并合并生成的web-archive中的所有内容。它没有考虑您使用的任何插件或其他目录。
另一方面,EmbeddedMaven构建整个项目,因此您可以使用包含所有必需类/依赖项的存档。
至于错误:package org.jboss.arquillian.junit does not exist
您似乎没有对类路径有正确的依赖关系。请分享您在pom.xml文件或依赖关系树中的<dependencies>
。