我正在尝试使用宁静运行器运行保证测试的案例。但是我在作为junit test运行时遇到此错误:-
java.lang.TypeNotPresentException
我只想报告要使用宁静运行程序生成。无论如何,它可以解决。我没有在示例代码中出现任何错误。我进入junit结果的唯一错误。甚至我也尝试过其他版本的宁静。我在任何地方都找不到任何解决方案。
如果我没有在示例代码中添加此行@RunWith(SerenityRunner.class)
。然后可以,但是我得到了我不想要的正常报告。
下面是带有示例代码的pom.xml文件:-
<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>SerenityBDDImplement</groupId>
<artifactId>SerenityBDDImplement</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>SerenityBDD</name>
<properties>
<serenity.version>2.0.48</serenity.version>
<serenity.maven.version>2.0.48</serenity.maven.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<tags></tags>
<parallel.tests>4</parallel.tests>
<webdriver.base.url></webdriver.base.url>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/Test*.java</include>
<include>**/*TestSuite.java</include>
<include>**/When*.java</include>
</includes>
<systemPropertyVariables>
<webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
</systemPropertyVariables>
<parallel>classes</parallel>
<threadCount>${parallel.tests}</threadCount>
<forkCount>${parallel.tests}</forkCount>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<configuration>
<tags>${tags}</tags>
</configuration>
<executions>
<execution>
<id>serenity-reports</id>
<phase>post-integration-test</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
示例代码在这里:-
package com.serenitybdd.junit;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import io.restassured.RestAssured;
import net.serenitybdd.junit.runners.SerenityRunner;
import org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.equalTo;
@RunWith(SerenityRunner.class)
public class FirstTestSerenity {
@BeforeClass
public static void init() {
RestAssured.baseURI = "Rest URL";
}
@Test
public void getAllDetails() {
RestAssured.given()
.when()
.get("/get/all")
.then()
.log()
.all()
.statusCode(200);
}
@Test
public void verifyRecordCount() {
RestAssured.get("/get/KIT/all").then().assertThat()
.body("RestResponse.messages", hasItem("Total [0] records found."));
}
}