java - 无法使用 testng 配置运行我的测试类
问题描述
我对自己运行测试类有疑问。将我的 IntelliJ IDEA 从版本 2018 更新到 2020 后,我无法使用 testNG 自行运行测试,它通过 Gradle 运行并且不起作用。
我的 build.gradle
plugins {
id 'io.qameta.allure' version "2.4"
id "net.ltgt.apt" version "0.15"
}
allure {
version = '2.4.1'
autoconfigure = true
aspectjweaver = true
allureJavaVersion = '2.0-BETA9'
}
apply plugin: 'java-library'
apply plugin: "io.qameta.allure"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.1'
implementation 'org.testng:testng:6.11'
implementation 'org.seleniumhq.selenium:selenium-java:3.6.0'
implementation 'org.hamcrest:java-hamcrest:2.0.0.0'
implementation 'com.beust:jcommander:1.72'
implementation 'com.thoughtworks.xstream:xstream:1.4.8'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'ch.qos.logback:logback-classic:1.1.5'
implementation 'org.apache.poi:poi:3.17'
implementation 'org.apache.maven.plugins:maven-compiler-plugin:3.7.0'
implementation 'ru.yandex.qatools.ashot:ashot:1.5.4'
implementation 'io.rest-assured:rest-assured:4.2.0'
implementation 'org.projectlombok:lombok:1.18.16'
compileOnly 'org.projectlombok:lombok:1.18.16'
annotationProcessor 'org.projectlombok:lombok:1.18.16'
testCompileOnly 'org.projectlombok:lombok:1.18.16'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.16'
// DB
implementation("org.hibernate:hibernate-core:5.3.10.Final")
implementation("mysql:mysql-connector-java:8.0.16")
/*def excludeLog = {exclude group: 'ch.qos.logback:logback-core', 'ch.qos.logback:logback-classic'}
compile 'net.sourceforge.tess4j:tess4j:4.2.2', excludeLog*/
/*def excludeLog = {exclude group: 'ch.qos.logback:logback-core', 'ch.qos.logback:logback-classic'}*/
implementation 'net.sourceforge.tess4j:tess4j:4.3.1'
implementation group: 'org.springframework', name: 'spring-web', version: '3.0.2.RELEASE'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.5'
//Gmail
implementation 'com.google.api-client:google-api-client:1.23.0'
implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
implementation 'com.google.apis:google-api-services-gmail:v1-rev83-1.23.0'
//ftp client
implementation group: 'commons-net', name: 'commons-net', version: '3.6'
}
task testLttTestServer(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/testng-ltt-test-regression.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testLttProdServer(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/testng-ltt-prod-regression.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testKparserProdServer(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/testng-kparser-prod-regression.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testSeo(type: Test) {
if (project.hasProperty('jsonName')) {
systemProperty 'jsonName', "${jsonName}"
}
useTestNG() {
suites 'src/test/resources/testNG/testng-SeoUtil-test.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testSitecheckerDB(type: Test) {
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsalt', "${pswsalt}"
}
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsk', "${pswsk}"
}
useTestNG() {
suites 'src/test/resources/testNG/dbTests/testng-sitechecker-position-test.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testSitecheckerNotifications(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/testng-sitechecker-notifications.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testCopywritely(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/testng-copywritely-regression.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task testSitecheckerNewUI(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/SCnew.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task crawlerTest(type: Test) {
useTestNG() {
suites 'src/test/resources/testNG/sitechecker-crawling-test.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task alxLocalhostTest(type: Test) {
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsalt', "${pswsalt}"
}
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsk', "${pswsk}"
}
useTestNG() {
suites 'src/test/resources/testNG/alx-test.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task noMonitoringTest(type: Test) {
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsalt', "${pswsalt}"
}
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsk', "${pswsk}"
}
useTestNG() {
suites 'src/test/resources/testNG/dbTests/noMonitoringTest.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task inProgressDomainsTest(type: Test) {
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsalt', "${pswsalt}"
}
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsk', "${pswsk}"
}
useTestNG() {
suites 'src/test/resources/testNG/dbTests/testng-sitechecker-inProgressDomain-test.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
task userWorkFlowTest(type: Test) {
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsalt', "${pswsalt}"
}
if (project.hasProperty('pswsalt')) {
systemProperty 'pswsk', "${pswsk}"
}
useTestNG() {
suites 'src/test/resources/testNG/testng-sitechecker-prod-UserWorkFlowtest.xml'
useDefaultListeners = true
}
reports.html.enabled = false
}
我仍然可以使用 testNG 毫无问题地运行任何 xml 文件,但无法理解单个配置类发生了什么。
解决方案
该问题已通过将 gradle 运行配置中的值“运行测试”从“gradle”更改为“intelliJ”来解决
推荐阅读
- r - 在 Linux 上根据 Windows-1252 进行 R char 排序
- python - TypeError: individual_success_handle() 缺少 4 个必需的位置参数:“request_type”、“name”、“response_time”和“response_length”
- javascript - 谷歌地图,带有多个距离标记和聚类的路线
- javascript - 交叉点观察者中有 entry.target.Classname 吗?
- c++ - 为什么 C++ 总是显示一个十六进制的内存地址而不仅仅是一个整数?
- android - 我应该在使用 viewModel 时添加 binding.lifecycleOwner=this 吗?
- html - Jquery不在父循环内循环
- java - OutputStream 未完全写入 mp3
- c++ - 整数数组 [n] 与新整数 [n]
- nlp - NLP:从 QuestionAnsweringPipeline 中获得 5 个最佳候选人