我有一个使用TestNG运行的简单代码,但我无法使用Gradle运行相同的内容,因为它说没有找到主要方法,这也就是说,因为我正在使用注释,这并不奇怪.
但在这种情况下,如果必须使用Gradle,如何运行代码.
请注意,我对Gradle很新,并且对此并不了解.
码:
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class tryTestNG
{
@BeforeClass
public void setup()
{
System.out.println("I am in Setup");
}
@Test
public void test()
{
System.out.println("I am in Test");
}
@AfterClass
public void tearDown()
{
System.out.println("I am in tearDown");
}
}
Run Code Online (Sandbox Code Playgroud)
上面的代码与TestNG Library完美搭配.但不是Gradle.
这是我的Gradle Build设置:
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'tryTestNG'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
test {
useTestNG()
}
dependencies {
compile group: 'org.testng', name: 'testng', version: '6.9.10'
}
Run Code Online (Sandbox Code Playgroud)
Gradle返回没有主方法.
Working Directory: /home/avirup/MyWorkspace/JavaWorkspace/TestNGGradle
Gradle User Home: /home/avirup/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 2.9
Java Home: /usr/lib/jvm/java-8-oracle
JVM Arguments: None
Program Arguments: None
Gradle Tasks: run
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:runError: Main method not found in class tryTestNG, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-8-oracle/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 0.514 secs
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
没有必要使用application插件来运行测试.
本build.gradle应该是:
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '1.0'
repositories {
mavenCentral()
}
test {
useTestNG()
}
dependencies {
compile group: 'org.testng', name: 'testng', version: '6.9.10'
}
Run Code Online (Sandbox Code Playgroud)
命令:gradle test.此外,把tryTestNG下src/test/java与大写字母命名.
这是一个演示.
还要注意,println测试中的语句在控制台中不可见.要查看它们,请导航到测试报告.它在:<project_dir>/build/reports/tests/index.html.
| 归档时间: |
|
| 查看次数: |
6051 次 |
| 最近记录: |