我看过其他频道,但我没有太多运气来回答我的问题。
我正在开发一个最初使用TestNG 5.14.10编写的测试代码库,并在我的build.gradle
文件中将其更新为6.8.7(我使用Gradle + Maven作为依赖项)。
我的构建文件如下(包括TestNG的新版本#):
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
repositories {
mavenCentral()
}
dependencies {
compile "org.seleniumhq.selenium:selenium-java:2.38.0"
compile "org.testng:testng:6.8.7"
testCompile('org.uncommons:reportng:1.1.2') {
exclude group: 'org.testng'
}
testCompile "junit:junit:4.8.2"
compile "com.jayway.restassured:rest-assured:1.8.1"
}
//initialize thread count variable for parallel testing and default to 1
def threadCount = System.getProperty("MAXTHREADS", "1")
tasks.withType(Test) {
maxParallelForks = 1
forkEvery = 1000
ignoreFailures = false
// Pass all system properties to the tests
systemProperties = System.getProperties()
// Makes the standard streams (err and out) visible at console when running tests
testLogging.showStandardStreams = true
exclude '**/tasks/'
classpath += configurations.testCompile
}
task firefox(type: Test) {
maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
testLogging.events "started"
testLogging {
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full" // default is "short"
}
useTestNG() {
excludeGroups 'chrome', 'broken'
useDefaultListeners = false
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/firefox")
testReportDir = file("${reporting.baseDir}/firefox")
systemProperties.BROWSER = System.getProperty('BROWSER', 'firefox')
exclude '**/selenium/'
exclude '**/setupscripts/'
}
task chrome(type: Test) {
maxParallelForks = Integer.valueOf(threadCount) //default is 1 if not specified
testLogging {
events "started", "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat "full"
}
useTestNG() {
excludeGroups 'broken'
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/chrome")
testReportDir = file("${reporting.baseDir}/chrome")
systemProperties.BROWSER = System.getProperty('BROWSER', 'chrome')
exclude '**/selenium/'
exclude '**/setupscripts/'
}
task internetExplorer(type: Test) {
useTestNG() {
excludeGroups 'chrome', 'broken'
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testReportDir = file("${reporting.baseDir}/internetExplorer")
testResultsDir = file("${buildDir}/test-results/internetExplorer")
systemProperties.BROWSER = System.getProperty('BROWSER', 'internetExplorer')
exclude '**/selenium/'
exclude '**/setupscripts/'
}
task applylicense(type: Test) {
useTestNG() {
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/applyLicense")
testReportDir = file("${reporting.baseDir}/applyLicense")
scanForTestClasses = false
include '**/setupscripts/ApplyLicense.class'
}
task uatsetup(type: Test) {
useTestNG() {
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/uatSetup")
testReportDir = file("${reporting.baseDir}/uatSetup")
scanForTestClasses = false
include '**/setupscripts/UatSetup.class'
}
task restsetup(type: Test) {
useTestNG() {
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/restSetup")
testReportDir = file("${reporting.baseDir}/restSetup")
scanForTestClasses = false
include '**/setupscripts/RestSetup.class'
}
task soapsetup(type: Test) {
useTestNG() {
useDefaultListeners = false;
listeners << 'org.uncommons.reportng.HTMLReporter'
listeners << 'org.uncommons.reportng.JUnitXMLReporter'
listeners << 'com.xmatters.testng.Listener'
}
testResultsDir = file("${buildDir}/test-results/soapSetup")
testReportDir = file("${reporting.baseDir}/soapSetup")
scanForTestClasses = false
include '**/setupscripts/SoapSetup.class'
}
task selenium(type: Test) {
testResultsDir = file("${buildDir}/test-results/selenium")
testReportDir = file("${reporting.baseDir}/selenium")
include '**/selenium/'
exclude '**/webdriver/'
exclude '**/*$*', '**/Abstract*'
exclude '**/messagepanel/'
exclude '**/propertylibrary/'
}
javadoc() {
title = "xMod Page Objects API"
}
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
我使用--debug和--stacktrace参数为一个任务运行了一个构建(包含两个注释和处理类似于标准测试的安装脚本)。似乎测试被设置为通过然后失败。非常离奇的行为。看来这是某种向后兼容性问题。我通常在没有问题的情况下针对一组约500个测试运行,唯一的变化是我的TestNG bersion。这是我的shell命令和结果输出(我把它修剪成我认为相关的行,因为调试模式非常详细):
./gradlew uatsetup -DREMOTE_DRIVER=false -DWEB_SERVER=10.3.1.226:8888 --stacktrace --debug
由于尺寸:http://pastebin.com/wsczwgT9
,必须使用PasteBin作为我的调试输出任何帮助都会很棒。
干杯,
达尔文
答案 0 :(得分:1)
我不熟悉Gradle,但在我的Maven设置中,当没有Maven依赖项下载到我的工作站时(类似于'mvn clean'),我通常会看到java.lang.ClassNotFoundException。
运行'mvn install'可以帮我完成工作。
只需确保您的PC上有必要的库,JAR等。
答案 1 :(得分:1)
嗯,经过一番挖掘,我找到了答案。较新版本的TestNG似乎需要Google guice库。我将此添加到我的依赖项中,似乎已解决了该问题。发生的事情是测试正在通过,但由于缺少依赖性而导致报告被破坏,并将整个构建(和测试)标记为失败。
我在依赖项声明中添加了以下行:
compile "com.google.inject:guice:3.0"
不知道为什么这个库需要更清楚,但我想这就是它的原因。无论如何,问题已经解决了。