【发布时间】:2019-07-09 23:51:39
【问题描述】:
我正在尝试使用 IntelliJ IDEA 使用 Serenity BDD 框架运行 junit 测试。
当我尝试运行测试时出现错误:
java.lang.Exception: No tests found matching Method ... from org.junit.internal.requests.ClassRequest@71e693fa
这似乎是由于使用 RunWith 注释调用 SerenityParameterizedRunner
@RunWith(SerenityParameterizedRunner.class)
当 RunWith 注释被注释掉时,测试被找到并开始执行(虽然这没什么用,因为我们依赖 Parameterized runner 来构建数据)。
我能够通过一个简单的项目重现该问题以演示该问题。
package com.home;
public class Doorbell {
private int ringCount = 0;
public Doorbell() {
}
public void ring(){
System.out.println("Ring!");
ringCount++;
}
public int getRings() {
return ringCount;
}
}
测试类:
package com.home;
import net.serenitybdd.junit.runners.SerenityParameterizedRunner;
import net.serenitybdd.junit.runners.SerenityRunner;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(SerenityParameterizedRunner.class)
public class DoorbellTest {
@Test
public void testRings()
{
Doorbell db = new Doorbell();
db.ring();
db.ring();
Assert.assertEquals(2,db.getRings());
}
}
Pom.xml
<?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>
<groupId>homeproject</groupId>
<artifactId>mytestproject</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<serenity.version>1.9.31</serenity.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>1.9.31</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>1.9.31</version>
</dependency>
</dependencies>
</project>
请尝试在项目中运行单个单元测试。非常感谢任何帮助。
【问题讨论】:
-
你为什么用
SerenityParameterizedRunner不带任何参数? AFAIK 这需要@TestData以及使用 testdata 作为参数的公共构造函数。 -
没有将它添加到这个测试类,因为我能够重现这个问题。在实际项目中,我使用@UseTestDataFrom,从csv文件中读取
标签: java junit serenity-bdd