java htmltestrunner_如何从java TestRunner类运行黄瓜测试

结果:

/opt/gradle/gradle-2.7/bin/gradle clean cucumber uberJar

:clean

:compileJava

warning: [options] bootstrap class path not set in conjunction with -source 1.6

1 warning

:compileGroovy UP-TO-DATE

:processResources UP-TO-DATE

:classes

:jar

:startScripts

:distTar

:distZip

:assemble

:cucumber

# language: en

Feature: Division

In order to avoid silly mistakes

Cashiers must be able to calculate a fraction

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".

SLF4J: Defaulting to no-operation (NOP) logger implementation

SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

@important

Scenario: Regular numbers # calc/division.feature:7

Given I have entered 3 into the calculator # CalculatorSteps.groovy:31

And I have entered 2 into the calculator # CalculatorSteps.groovy:31

When I press divide # CalculatorSteps.groovy:39

Then the stored result should be 1.5 # CalculatorSteps.groovy:43

Scenario: More numbers # calc/division.feature:13

Given I have entered 6 into the calculator # CalculatorSteps.groovy:31

And I have entered 3 into the calculator # CalculatorSteps.groovy:31

When I press divide # CalculatorSteps.groovy:39

Then the stored result should be 2.0 # CalculatorSteps.groovy:43

2 Scenarios (2 passed )

8 Steps (8 passed )

0m0.186s

:uberJar

BUILD SUCCESSFUL

Total time: 19.643 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.7/userguide/gradle_daemon.html

如何在Java文件中运行相同的测试:例如

的src /主/爪哇/钙/ TestRunner.java

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

import org.junit.runner.notification.Failure;

@RunWith(Cucumber.class)

@CucumberOptions(format = {"pretty"}, monochrome=true)

public class TestRunner {

public static void main(String[] args) {

System.out.println("dummy main java");

// I want to run the tests from within the jar file

}

}

所以当我做java -jar build / distributions / cucumber-jvm-groovy-example.jar时

我应该得到与使用gradle通过命令行运行测试时相同的结果

我使用了以下Java类:

import org.junit.*;

import org.junit.runner.JUnitCore;

import org.junit.runner.Result;

import org.junit.runner.notification.Failure;

import cucumber.api.CucumberOptions;

import cucumber.api.junit.Cucumber;

import org.junit.runner.RunWith;

import java.util.ArrayList;

import java.util.List;

import org.junit.runner.notification.Failure;

@RunWith(Cucumber.class)

@CucumberOptions(format = {"pretty"}, monochrome=true)

public class TestRunner {

public static void main(String[] args) {

System.out.println("dummy main java");

JUnitCore.main("cucumberTest.TestRunner");

}

}

但有例外:

initializationError(org.junit.runner.JUnitCommandLineParseResult)

java.lang.IllegalArgumentException: Could not find class [cucumberTest.TestRunner]

at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCommandLineParseResult.java:102)

at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLineParseResult.java:50)

at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLineParseResult.java:44)

at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)

at org.junit.runner.JUnitCore.main(JUnitCore.java:36)

at TestRunner.main(TestRunner.java:19)

Caused by: java.lang.ClassNotFoundException: cucumberTest.TestRunner

这使我认为JUnitCore.main()需要一个类名作为参数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值