I am using a simple java application with unit and integration tests. my goal is to run integration tests with maven & failsafe plugin. I am having a problem running my integration tests. short explenation: I get an error from "test-compile" phase at maven, which says "cannot find symbol".
project structure:
- parent (pom.xml)
- integration test module (test files with pom.xml)
- webApp module (source files with pom.xml)
the error I am getting is becouse I am trying to instantiate an object from webApp module (inside some test - in integration tests module). I also added dependency for webapp inside integration-test module pom.
details:
the integration test class:
import junit.framework.TestCase;
import org.junit.Test;
public class CalcsITCase extends TestCase {
@Test
public void emptyTest() throws Exception {
assertEquals(true,true);
}
@Test
public void playTest() throws Exception {
Band band = new Band(4);
assertEquals(true,true);
}
}
the class that being tested
import org.json.JSONObject;
import java.security.InvalidParameterException;
public class Band {
public int id;
public String name = "";
public String logo = "";
public String song = "";
public int votes = 0;
public Band(int members) {
System.out.println(members + " members in band");
}
....
The integration test pom.xml:
<project xmlns="http://ift.tt/IH78KX" xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/HBk9RF">
<parent>
<artifactId>app-all</artifactId>
<groupId>discover-demo-app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>integration-tests</artifactId>
<packaging>jar</packaging>
<name>integration-tests Maven Webapp</name>
<url>http://ift.tt/19pvvEY;
<dependencies>
<dependency>
<groupId>discover-demo-app</groupId>
<artifactId>webapp</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
<!-- <scope>test</scope>-->
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
<finalName>integration-tests</finalName>
</build>
<profiles>
<profile>
<id>it</id>
<build>
<plugins>
<!--added for integration tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>....</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>....</groupId>
<artifactId>....</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
the webApp pom.xml
<project xmlns="http://ift.tt/IH78KX" xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/HBk9RF">
<modelVersion>4.0.0</modelVersion>
<groupId>discover-demo-app</groupId>
<artifactId>webapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Discover Demo App - Tribute to Progressive Music (Web App)</name>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>webapp</finalName>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.5.201505241946</version>
<configuration>
<output>file</output>
<append>true</append>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>A</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- Minimal supported version is 2.4 -->
<version>2.13</version>
<configuration>
<skipTests>true</skipTests>
<properties>
<property>
<name>listener</name>
<value>...</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>it</id>
<build>
<plugins>
<!--added for integration tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<skipTests>false</skipTests>
<properties>
<property>
<name>listener</name>
<value>...</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>12.53.1-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
the error i am getting from maven (when running the following command inside integration test) is:
mvn verify -Dmaven.test.failure.ignore=true
[INFO] ------------------------------------------------------------------------
[INFO] Building integration-tests Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ integration-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\..\workspace\..\integration-tests\src\main\re
sources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ integration-tests ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ integration-tests ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\..\workspace\..-demo-app\integration-tests\src\test\re
sources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ integration-tests ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files to C:\Users\..\workspace\..e-demo-app\integration-tests\target\test-classes
[INFO] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/RestServle
tTest.java: C:\Users\..\workspace\..-demo-app\integration-tests\src\test\java\com\..\devops\demoapp\RestSe
rvletTest.java uses unchecked or unsafe operations.
[INFO] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/RestServle
tTest.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,9] cannot find symbol
symbol: class Band
location: class com....devops.demoapp.CalcsITCase
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,25] cannot find symbol
symbol: class Band
location: class com....devops.demoapp.CalcsITCase
[INFO] 2 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.676s
[INFO] Finished at: Tue Mar 01 11:45:17 IST 2016
[INFO] Final Memory: 16M/304M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.5.1:testCompile (default-testComp
ile) on project integration-tests: Compilation failure: Compilation failure:
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,9] cannot find symbol
[ERROR] symbol: class Band
[ERROR] location: class com....devops.demoapp.CalcsITCase
[ERROR] /C:/Users/../workspace/..-demo-app/integration-tests/src/test/java/com/../devops/demoapp/CalcsITCa
se.java:[20,25] cannot find symbol
[ERROR] symbol: class Band
[ERROR] location: class com.(..).devops.demoapp.CalcsITCase
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
Aucun commentaire:
Enregistrer un commentaire