Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mvn test doesn't run tests #823

Closed
Chralu opened this issue Jul 9, 2019 · 11 comments
Closed

mvn test doesn't run tests #823

Chralu opened this issue Jul 9, 2019 · 11 comments
Assignees
Milestone

Comments

@Chralu
Copy link

Chralu commented Jul 9, 2019

Hi all,

I'm having trouble executing Karate tests using Maven.
Any help is welcome ;)

Steps to reproduce :

Create a new project using archetype

mvn archetype:generate \
-DarchetypeGroupId=com.intuit.karate \
-DarchetypeArtifactId=karate-archetype \
-DarchetypeVersion=0.9.4 \
-DgroupId=com.mycompany \
-DartifactId=myproject

Run tests

$ cd myproject
$ mvn test

Expected

Tests are compiled, then run.

Actual

Tests are compiled, but never run. The folder target/surefire-reports doesn't exist.

Here is the mvn test output :

[INFO] Scanning for projects...
[INFO] 
[INFO] ----------------------< com.mycompany:myproject >-----------------------
[INFO] Building myproject 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /tmp/karate/myproject/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ myproject ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ myproject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:testCompile (default-testCompile) @ myproject ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /tmp/karate/myproject/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ myproject ---
[INFO] Surefire report directory: /tmp/karate/myproject/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.486 s
[INFO] Finished at: 2019-07-09T11:18:47+02:00
[INFO] ------------------------------------------------------------------------

About my environment

$ mvn --version
Apache Maven 3.6.1 (NON-CANONICAL_2019-05-22T16:10:23+02:00_root; 2019-05-22T16:10:23+02:00)
Maven home: /opt/maven
Java version: 1.8.0_222, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk/jre
Default locale: fr_FR, platform encoding: UTF-8
OS name: "linux", version: "5.1.15-arch1-1-arch", arch: "amd64", family: "unix"

Thanks :)

@ptrthomas ptrthomas self-assigned this Jul 9, 2019
@ptrthomas ptrthomas added the bug label Jul 9, 2019
@ptrthomas ptrthomas added this to the 0.9.5 milestone Jul 9, 2019
@ptrthomas
Copy link
Member

ptrthomas commented Jul 9, 2019

@Chralu thanks, we indeed missed a step in the archetype when moving to JUnit 5. You have 2 simple options

a) generate the archetype for 0.9.3 e.g. -DarchetypeVersion=0.9.3 and then edit the generated pom.xml by hand to <karate.version>0.9.4</karate.version> - so the project will use JUnit 4

b) or - add 2 sections to the pom.xml - note the junit-jupiter-engine dependencies/dependency and maven-surefire-plugin build/plugins/plugin added. here is the final pom.xml below for your reference, and the tests will be JUnit 5. we have fixed this for the next version.

<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>
 
    <groupId>com.mycompany</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.6.0</maven.compiler.version>
        <karate.version>0.9.4</karate.version>
    </properties>    

    <dependencies>
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-apache</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>            
        <dependency>
            <groupId>com.intuit.karate</groupId>
            <artifactId>karate-junit5</artifactId>
            <version>${karate.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.4.0</version>
            <scope>test</scope>
        </dependency>        		
    </dependencies>

    <build>
        <testResources>
            <testResource>
                <directory>src/test/java</directory>
                <excludes>
                    <exclude>**/*.java</exclude>
                </excludes>
            </testResource>
        </testResources>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerArgument>-Werror</compilerArgument>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>            
        </plugins>        
    </build>       
    
</project>

@ptrthomas ptrthomas added the fixed label Jul 9, 2019
@Chralu
Copy link
Author

Chralu commented Jul 9, 2019

Thanks @ptrthomas ! It works fine with JUnit5.
You made my day \o/

@Chralu Chralu closed this as completed Jul 9, 2019
@ptrthomas
Copy link
Member

@Chralu great ! thank you for raising this genuine issue, I updated the docs as well. I'll keep this open as something pending 0.9.5 when it will be properly fixed

@ptrthomas ptrthomas reopened this Jul 9, 2019
@ptrthomas
Copy link
Member

@yaci
Copy link

yaci commented Oct 27, 2019

I am facing similar problem with Gradle. I created new Gradle project in IntelliJ then generated another one from maven archetype and copied src/test/java from maven project to gradle one. When I am trying to execute ./gradlew test the build succeeds, but tests are not run.
Are there any extra imports required? I added junit-jupyter-engine, but it did not help. Here's my build.gradle file, could anyone tell me what am I doing wrong?

plugins {
    id 'java'
}

group 'karate-gradle'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    implementation('com.intuit.karate:karate-junit5:0.9.4')
    implementation('com.intuit.karate:karate-apache:0.9.4')
    implementation('org.junit.jupiter:junit-jupiter:5.5.2')
    implementation('org.junit.jupiter:junit-jupiter-engine:5.5.2')
    implementation('org.junit.jupiter:junit-jupiter-api:5.5.2')
}

test {
    include '**/*ExamplesTest*'
    useJUnitPlatform {
        includeEngines 'junit-jupyter'
    }
    testLogging {
        events "passed", "skipped", "failed"
        showStandardStreams = true
    }
    outputs.upToDateWhen { false }
}

@ptrthomas
Copy link
Member

@yaci only 2 suggestions. try with karate 0.9.5.RC3 also refer: https://github.com/intuit/karate/wiki/Gradle

@Artashes1996
Copy link

Artashes1996 commented Dec 14, 2019

@ptrthomas I was able to create a project and integrate Karate with maven and run tests, but when my colleagues are checkout my repo and want to run tests. We have an issue that says "Warning: Nashorn engine is planned to be removed from a future JDK release" And we have a problem with connection step definitions. Can you help us?
This is my email address "[email protected]"

@ptrthomas
Copy link
Member

@Artashes1996 use stack overflow for support please, or read: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

@ptrthomas
Copy link
Member

released 0.9.5

@reddyharinath
Copy link

@ptrthomas , I am new to this KARATE framework and implemented in eclipse in a maven project. feature files are executed without using in pom.xml, while creating CI job, updated pom.xml file with tag details, tests are not running. Could you please help me?
Test data & steps are updated below.
Environment:-
[Java-1.8]
Maven:- 3.8
Junit:- 5
Note:- i have updated the pom.xml file as per #823, but small change in build file.

pom.txt

org.apache.maven.plugins maven-compiler-plugin 3.8.1 UTF-8 1.8 1.8 -Werror
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<version>2.22.2</version>
			<configuration>
				<includes>
					<include>**/*JPAccountCreationRunner.java</include>
				</includes>
			</configuration>
		</plugin>

		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-failsafe-plugin</artifactId>
			<version>2.22.0</version>
			<configuration>
				<argLine>
					--illegal-access=permit
				</argLine>
			</configuration>
		</plugin>
	</plugins>
</build>

output:-
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/hdama/Downloads/eclipse-jee2/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.18.0.20210402-1458/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/C:/Users/hdama/Downloads/eclipse-jee2/eclipse/configuration/org.eclipse.osgi/6/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/hdama/Downloads/eclipse-jee2/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.18.0.20210402-1458/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/C:/Users/hdama/Downloads/eclipse-jee2/eclipse/configuration/org.eclipse.osgi/6/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------------< PayPal_Jp:JpLicenseProject >---------------------
[INFO] Building JpLicenseProject 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ JpLicenseProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ JpLicenseProject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ JpLicenseProject ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ JpLicenseProject ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ JpLicenseProject ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.194 s
[INFO] Finished at: 2021-09-29T16:03:00+05:30
[INFO] ------------------------------------------------------------------------

@ptrthomas
Copy link
Member

@reddyharinath I'm sorry I can't help unless you follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants