Search code examples
apiautomated-testskarateweb-api-testing

Karate API Testing @RunWith(Karate.class) Errror


Hello this is my first time trying an own API testing but I'm a little bit confused.

I want to test if DataCycle API is available and gives correct results, but i'm getting the Type mismatch error for Karate.class

Can someone find my mistake?

This is my feature file where i wanna check is its running

Feature: Karate testing DataCycle API

  Scenario: Verify DataCycle is up and running
  
    Given url https://datacycle.visitklagenfurt.at/api/v4/universal
    When method get
    Then status 200
package examples;

import org.junit.runner.RunWith;

import com.intuit.karate.junit5.Karate;

@RunWith(Karate.class)
public class Demo1 {

}

To be honest everything could be terribly wrong obviously because I am new to API testing

This is the HTTP-GET url: https://datacycle.visitklagenfurt.at/api/v4/endpoints/f9ef0685-36bd-404f-b53a-db52adc86d7c?token=04f9e0d4dd87173d29ebc9c7d1c64ac8

my pom.xml file:

 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>2.22.2</maven.surefire.version>        
        <karate.version>0.9.6</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>       
    </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>${maven.surefire.version}</version>
                <configuration>
                    <argLine>-Dfile.encoding=UTF-8</argLine>
                </configuration>
            </plugin>          
        </plugins>        
    </build>       
    
</project>

Solution

  • @RunWith(Karate.class) is only for JUnit 4.

    Please just start with the quickstart: https://github.com/intuit/karate#quickstart

    Or maybe the ZIP release will be simpler: https://github.com/intuit/karate/wiki/ZIP-Release