我是Gradle的新手。我能够通过testng运行我的测试用例,但是无法从Eclipse中与Gradle一起运行。
以下是 build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'selenium.webdriver.qa'
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// The production code uses the SLF4J logging API at compile time
compile 'org.slf4j:slf4j-api:1.7.21'
testCompile 'junit:junit:4.12'
repositories {
mavenCentral()
}
dependencies {
testCompile 'org.testng:testng:6.9.4'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version: '2.+'
compile group: 'junit', name: 'junit', version: '4.+'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.+'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.0.+'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.0.+'
}
test {
useTestNG(){
include "com.mca.automation.script.SanityTestScript"
}
}
test.testLogging {
showStandardStreams = true
}
当我运行测试课时。它显示以下错误:
D:\Project\SanityTestScript.java:4: error: package org.testng does not exist
import org.testng.Assert;
^
D:\Project\SanityTestScript.java:5: error: package org.testng.annotations does not exist
import org.testng.annotations.AfterTest;
^
D:\Project\SanityTestScript.java:6: error: package org.testng.annotations does not exist
import org.testng.annotations.BeforeTest;
^
D:\Project\SanityTestScript.java:7: error: package org.testng.annotations does not exist
import org.testng.annotations.Test;
^
D:\Project\SanityTestScript.java:18: error: cannot find symbol
@BeforeTest
^
symbol: class BeforeTest
location: class MCA_SanityTestScript
D:\Project\SanityTestScript.java:24: error: cannot find symbol
@Test
^
symbol: class Test
location: class MCA_SanityTestScript
D:\Project\SanityTestScript.java:51: error: cannot find symbol
@AfterTest
^
symbol: class AfterTest
location: class MCA_SanityTestScript
D:\Project\SanityTestScript.java:48: error: cannot find symbol
Assert.assertTrue(expEvent.equalsOnActiveUntilDate(actualEvent));
^
symbol: variable Assert
location: class SanityTestScript
8 errors
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
我不明白我到底在做什么错。甚至testng包也已经导入。使用Eclipse,因此将testng库添加到项目中。
最佳答案
在compileJava
任务期间,您的构建失败。这意味着您在主源集中的src/main/java
文件夹中拥有测试类,即使用TestNG的测试类。它们应位于测试源集中的src/test/java
文件夹中。
您已将TestNg库添加到testCompile
配置中,这是正确的。但这也意味着此库仅添加到类路径中以用于测试编译和运行。不适用于主应用程序的编译和运行。而且您似乎在应用程序类中有测试类。
关于selenium - 如何使用testng配置gradle,已导入软件包但出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39031758/