【问题标题】:Java Cucumber - Junit "Could not find class" in command lineJava Cucumber - Junit在命令行中“找不到类”
【发布时间】:2016-10-23 21:23:07
【问题描述】:

尝试做一些自动化测试。当我尝试在命令行中执行 junit 时出现错误,

尝试的命令

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore C:/Users/path/workspace/CucumberConcept/src/ cucumber.CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar;C:/Users/path/workspace/CucumberConcept/src/ org.junit.runner.JUnitCore cucumber.CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore CucumberConcept.src.cucumber.CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore cucumber.CucumberRunner.CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore CucumberRunner.CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore CucumberRunner CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore CucumberRunner.java CucumberRunner

java -cp C:/Users/path/Downloads/selenium-java-3.0.1/lib/junit-4.12.jar org.junit.runner.JUnitCore CucumberRunner

Junit 代码:

package cucumber;

import org.junit.runner.RunWith;

import cucumber.api.junit.*;
import cucumber.api.CucumberOptions;


@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty","json:target/json/output.json","html:target/html/"},
        features = {"src/cucumber/"}
        )
public class CucumberRunner {
}

命令行

C:\Users\path\CucumberConcept\src>java -classpath C:/Users/path/lib/junit-4.12.jar;classes org.junit.runner.JUnitCore cucumber.CucumberRunner

JUnit version 4.12
.E
Time: 0.004
There was 1 failure:
1) initializationError(org.junit.runner.JUnitCommandLineParseResult)
java.lang.IllegalArgumentException: Could not find class [cucumber.CucumberRunne
r]
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCom
mandLineParseResult.java:102)
        at org.junit.runner.JUnitCommandLineParseResult.parseArgs(JUnitCommandLi
neParseResult.java:50)
        at org.junit.runner.JUnitCommandLineParseResult.parse(JUnitCommandLinePa
rseResult.java:44)
        at org.junit.runner.JUnitCore.runMain(JUnitCore.java:72)
        at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
Caused by: java.lang.ClassNotFoundException: cucumber.CucumberRunner
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.junit.internal.Classes.getClass(Classes.java:16)
        at org.junit.runner.JUnitCommandLineParseResult.parseParameters(JUnitCom
mandLineParseResult.java:100)
        ... 4 more

FAILURES!!!
Tests run: 1,  Failures: 1

【问题讨论】:

    标签: java command-line junit cucumber automated-tests


    【解决方案1】:

    您的类路径已损坏。

    你能使用像 Maven 这样的构建工具吗?这可能比手动构建类路径要容易得多。

    克隆或下载 Cucumber 团队提供的 Java 框架,看看你能不能让它运行起来。可以在这里找到:https://github.com/cucumber/cucumber-java-skeleton

    如果您无法使用 Maven、Ant 或 Gradle,请查看 build.xml 以获取有关如何手动构建类路径的一些灵感。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-01
      • 1970-01-01
      • 2015-06-23
      • 1970-01-01
      • 2019-10-22
      相关资源
      最近更新 更多