简体   繁体   中英

how to run integration test for a web application with intellij and maven

I am migrating a web application in java from ANT to MAVEN, for problems with libraries and dependencies. I'm using the IDE "intellij IDEA 14".

i move the .java files to the main/java folder, shift resources (.properties and XML) to a folder main/resources folder and I moved my .jsp files to the main/webapps folder. i already have an executable version of the application without dependency problems.

Now I'm having problems with the TDD, I move the test files to the test/java folder but when i run the integration tests it all fail because they can not find the resources of the webapps folder.

More precisely tests that fail are those who checked the reports made with jasper-report that are in a report folder inside the webapps.

When looking at the generated folders in the target folder I see that I have a "test-classes" folder with the .class of each tdd and "classes" folder with the .class of the source code but nowhere see webapps files.

The test run without problem in the version with ant, when i build in ANT it generate a project folder with the files in the webapps folder and in WEB-INF/classes the .class files of the source code and the TDD.

I check that the folders are properly set 在此处输入图片说明

These tests look if the jrxml files exist in the module/report folder in the view folder, using the file path: ../../../modulo/reporte/file_name.

the class that generates the file path of the report is in project/web-inf/classes/system and use the following code:

URL path = Constantes.class.getResource (rutaReporte)

After that checks if they compile and return a valid result (full JasperPrint)

What I have to do to run integration tests en MAVEN using Intellij?

i fix it using "maven-resources-plugin" plugin to copy all webapp resources to test-classes so the tdd can find the resources to test

here is my pom config:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    ...


    <build>
    ...

        <plugins>
            ...

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>additional-resources</id>
                        <phase>process-test-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src/main/webapp</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM