我有多个测试作为 Android Jenkins 构建的一部分运行,包括单元测试和功能测试。我能够在 Jenkins 上成功发布测试结果,但我想查看单元测试和功能测试的单独结果图。Jenkins JUnit 发布者只为多个 XML 文件显示一个图表。有什么帮助吗?
从Intellij启动时,kotlintest测试运行良好,但是当我尝试使用gradle test task命令运行它们时,仅发现并运行了我的常规JUnit测试。
kotlintest代码:
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.StringSpec
class HelloKotlinTest : StringSpec() {
init {
println("Start Kotlin UnitTest")
"length should return size of string" {
"hello".length shouldBe 5
}
}
}
Run Code Online (Sandbox Code Playgroud)
build.gradle:
apply plugin: 'org.junit.platform.gradle.plugin'
buildscript {
ext.kotlinVersion = '1.1.3'
ext.junitPlatformVersion = '1.0.0-M4'
repositories {
maven { url 'http://nexus.acompany.ch/content/groups/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion"
}
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
test.kotlin.srcDirs += 'test/main/kotlin'
}
(...)
dependencies {
// Kotlin
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: kotlinVersion …Run Code Online (Sandbox Code Playgroud) 我androidx.test在我的项目中使用库(我最近迁移到的)并使用自定义AndroidJUnitRunner. 迁移之前一切正常,但现在我收到此错误 -
Started running tests
Test running failed: Instrumentation run failed due to 'Process crashed.'
Empty test suite.
我使用的自定义跑步者类扩展自androidx.test.runner.AndroidJUnitRunner
在我的应用程序build.gradle文件中,我有以下设置 -
testInstrumentationRunner "com.example.CustomTestRunner"
具有依赖关系 -
androidTestImplementation "androidx.test.ext:junit:1.1.0"
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:core:1.1.0'
androidTestImplementation "androidx.test:rules:1.1.1"
我所有的测试课都有@RunWith(androidx.test.ext.junit.runners.AndroidJUnit4.class)
我被困在这个问题上。任何帮助,将不胜感激。谢谢。
是否有可能让TestRunner运行以编程方式创建的测试套件?
例如,Block4JunitTestRunner将Suite类作为构造函数参数.但是,我不能这样做,因为套件不是具体套件.我动态地将TestCases添加到TestSuite,现在我需要一个TestRunner来运行它,所以我能够让Junit正常报告测试失败/成功/错误.(
谢谢.
在一个项目中,有多个测试类,每个测试类包含多个测试方法.比如,我想在运行每个测试类之前创建数据库连接.无论我是运行单个测试类,多个测试类还是测试套件,都应该建立连接.最重要的是,在多个测试类的情况下,不应该反复调用此步骤.无论我正在运行的测试类的数量如何,都应该只进行一次连接.
你能否提出一个设计或任何JUnit技巧来解决这个问题?
我有一些单元测试,当我尝试运行时,它会自动创建Maven运行/调试配置,而不是JUnit(集成的 IDEA 选项卡)。
对于某些测试,它确实使用 JUnitrun\debug configuration和手动 - 我可以同时创建Maven和JUnit.
如何让 JUnit 成为默认的测试运行器?
我是自动化测试的新手.我想运行一个特定的测试类,即使我有测试套件,它也会输出为
"客户还没准备好......测试运行开始......测试完成了......空测试套件......"
我搜索过并发现了很多解决方案.但他们都没有为我工作.如果我能得到任何帮助,我将不胜感激.这是测试文件.
package com.smsbits.veridoc.activity;
@RunWith(AndroidJUnit4.class)
public class TempActivityEspressoTest {
public Resources resources;
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(TempActivity.class);
@Before
public void init() {
resources = mActivityRule.getActivity().getResources();
}
@Test
public void testCheckInputs() {
onView(withId(R.id.btnchange)).perform(click());
onView(withId(R.id.tvrandom)).check(ViewAssertions.matches(withText("hello")));
}}
Run Code Online (Sandbox Code Playgroud)
这是我的gradle文件.
android {
...
packagingOptions {
...
exclude 'META-INF/XXX'
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
}
defaultConfig {
...
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
testOptions {
unitTests.returnDefaultValues = true
}
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:23.0.1'
}
}
dependencies{ …Run Code Online (Sandbox Code Playgroud) android ui-testing ui-automation junit-runner android-espresso
对于我使用以下模板的套房:
@RunWith(JUnitPlatform.class)
@SelectPackages("com.services.configuration")
@ExcludeTags({IntegrationTags.JPA, IntegrationTags.REST})
public class UnitTestSuite {
}
Run Code Online (Sandbox Code Playgroud)
@RunWith 是 JUnit 4 依赖项,它来自
compile "org.junit.platform:junit-platform-runner:1.0.2"
Run Code Online (Sandbox Code Playgroud)
是否可以在没有 JUnit 4 依赖项的情况下拥有 JUnit 5 套件?这样我就可以从我的依赖项中删除 JUnit 4?
不能用适当的@ExtendsWith扩展名替换吗?我只需要套房。
由于我们出于单元测试目的从 junit4 升级到 junit5,我无法找到在 junit5 中创建测试套件的解决方案,就像在 junit4 中一样:下面是我们的 junit4 套件类:
@RunWith(Suite.class)
@SuiteClasses({
ClassA.class,
ClassB.class,
ClassC.class
} )
public class TestSuite {
}
Run Code Online (Sandbox Code Playgroud)
我搜索后尝试的代码如下:
@RunWith(JUnitPlatform.class)
@SelectClasses( {
OrderAnnotationAlphanumericExperiment.class,
orderAnnotationExperiment.class,
ParameterizedAnnotation.class
} )
public class TestSuite {
}
Run Code Online (Sandbox Code Playgroud)
在寻找解决方案时,他们中的大多数人都提供了使用相同的测试套件来使用 vintage api 运行它的解决方案,但我正在寻找的是在 junit 5 中创建测试套件。
很少有人建议@ExtendsWith(SpringExtension.class),但它的文档也较少,无法找到在 junit 5 中创建套件的解决方案
我提到的一些博客/问题/网站:
在 JUnit5 (Eclipse) 中创建 TestSuite 测试 套件在 JUnit5 中是否被视为已弃用? https://howtodoinjava.com/junit5/junit5-test-suites-examples/
有人帮我解决这个问题。
我有一个 spring boot 应用程序,当我删除基本应用程序测试时,它无一例外地运行。但是当我添加应用程序测试类时它显示以下异常
{"@timestamp":"2018-04-23T18:10:39.421+05:30","@version":1,"message":"The following profiles are active: development","logger_name":"com.tmobile.u2.uprising.adjustment.AdjustmentApplicationTests","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:44.914+05:30","@version":1,"message":"HikariPool-1 - Starting...","logger_name":"com.zaxxer.hikari.HikariDataSource","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:44.958+05:30","@version":1,"message":"Registered driver with driverClassName=oracle.jdbc.driver.OracleDriver was not found, trying direct instantiation.","logger_name":"com.zaxxer.hikari.util.DriverDataSource","thread_name":"main","level":"WARN","level_value":30000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:48.794+05:30","@version":1,"message":"HikariPool-1 - Start completed.","logger_name":"com.zaxxer.hikari.HikariDataSource","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:49.315+05:30","@version":1,"message":"HHH000204: Processing PersistenceUnitInfo [\n\tname: default\n\t...]","logger_name":"org.hibernate.jpa.internal.util.LogHelper","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:49.847+05:30","@version":1,"message":"HHH000412: Hibernate Core {5.0.12.Final}","logger_name":"org.hibernate.Version","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:49.857+05:30","@version":1,"message":"HHH000206: hibernate.properties not found","logger_name":"org.hibernate.cfg.Environment","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:49.864+05:30","@version":1,"message":"HHH000021: Bytecode provider name : javassist","logger_name":"org.hibernate.cfg.Environment","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:50.076+05:30","@version":1,"message":"HCANN000001: Hibernate Commons Annotations {5.0.1.Final}","logger_name":"org.hibernate.annotations.common.Version","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:50.839+05:30","@version":1,"message":"HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect","logger_name":"org.hibernate.dialect.Dialect","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:54.583+05:30","@version":1,"message":"HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead. See Hibernate Domain Model Mapping Guide for details.","logger_name":"org.hibernate.orm.deprecation","thread_name":"main","level":"WARN","level_value":30000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:56.251+05:30","@version":1,"message":"HikariPool-1 - Shutdown initiated...","logger_name":"com.zaxxer.hikari.HikariDataSource","thread_name":"main","level":"INFO","level_value":20000,"APP_NAME":"adjustmentPublisher"}
{"@timestamp":"2018-04-23T18:10:57.467+05:30","@version":1,"message":"HikariPool-1 …Run Code Online (Sandbox Code Playgroud) 我正在用IntelliJ编写Selenium Junit测试。如果我直接从测试中触发,则测试运行正常。但是,如果我使用JunitCore触发了来自TestRunnerSuite的测试,则会遇到以下奇怪的错误,在谷歌搜索后我找不到解决方案。在DriverService $ builder上有类似的问题,但不是我的错误类型。
[main] ERROR sire.responseOrg.TestIncidents - java.lang.AbstractMethodError: org.openqa.selenium.remote.service.DriverService$Builder.createArgs()Lcom/google/common/collect/ImmutableList;
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:332)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.util1.setupChromeDriver(util1.java:51)
at sire.responseOrg.Test1.setUp(Test1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at ......Omitted
at org.junit.runner.JUnitCore.run(JUnitCore.java:127)
at org.junit.runner.JUnitCore.runClasses(JUnitCore.java:76)
at sire.responseOrg.TestSuiteRunner.main(TestSuiteRunner.java:24)
Run Code Online (Sandbox Code Playgroud)
我正在使用Selenium 3.5.3和chrome76。--->已更新为Selenium 3.141.59,并具有main范围。
现在出现错误
java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials
at org.openqa.selenium.remote.HttpCommandExecutor.getDefaultClientFactory(HttpCommandExecutor.java:93)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:72)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:63)
at org.openqa.selenium.chrome.ChromeDriverCommandExecutor.<init>(ChromeDriverCommandExecutor.java:36)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at sire.responseOrg.WebDrivers.getInstance(WebDrivers.java:15)
at sire.responseOrg.util.SeleniumUtil.setupChromeDriver(SeleniumUtil.java:62)
at sire.responseOrg.TestIncidents.setUp(TestIncidents.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
at …Run Code Online (Sandbox Code Playgroud) 一位同事最近在我们团队的项目中引入了Spock单元测试,并且我在Eclipse集成方面遇到了一个恼人的问题:每当我们创建参数化测试并在其上使用@Unroll注释时,Eclipse JUnit视图就会失去与它的关联.测试类并在"无根测试"下显示结果.
例如,此测试类的结果:
package test
import spock.lang.Specification
import spock.lang.Unroll
class TestSpockTest extends Specification {
def "Not Unrolled Test"() {
when: "something"
then: "one equals one"
1 == 1
}
@Unroll
def "Unrolled Test #param"(Integer param) {
when: "something"
then: "a numer equals itself"
param == param
where:
param << [1, 2, 3]
}
}
Run Code Online (Sandbox Code Playgroud)
以这种方式显示:

如何将展开的测试用例(例如"展开的测试1")显示在"test.TestSockTest"下,如"未展开的测试"?我的Spock测试是否有一些Eclipse JUnit插件可以理解的命名约定?
我正在使用:
junit-runner ×12
junit ×8
java ×5
android ×3
junit4 ×3
junit5 ×2
spring-boot ×2
unit-testing ×2
build.gradle ×1
eclipse ×1
groovy ×1
guava ×1
kotlin ×1
kotlintest ×1
maven ×1
selenium ×1
spock ×1
ui-testing ×1