在RunWith批注中使用SerenityParameterizedRunner进行的junit测试:未找到测试(java.lang.Exception:未找到与Method匹配的测试)

时间:2019-02-15 19:42:14

标签: java junit serenity-bdd

我正在尝试使用IntelliJ IDEA在Serenity BDD框架上运行junit测试。

尝试运行测试时出现错误:

the website is not redirecting properly

这似乎是由于使用RunWith注释调用了SerenityParameterizedRunner

java.lang.Exception: No tests found matching Method ... from org.junit.internal.requests.ClassRequest@71e693fa

注释掉RunWith注释后,就可以找到测试并开始执行测试(尽管这没有多大用处,因为我们依靠Parameterized运行器来构建数据)。

我可以用一个简单的项目重现该问题,以演示该问题。

@RunWith(SerenityParameterizedRunner.class)

测试类:

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;
    }
}

Pom.xml

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());
    }
}

Plesae尝试在项目中运行单个单元测试。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

Answer 11 from this Stack Overflow question解决了我的问题

显然,您必须运行包含测试的类,而不是测试本身。