草庐IT

Junit-Tests

全部标签

java - 如何使用参数化运行 JUnit SpringJUnit4ClassRunner?

由于重复的@RunWith注解,以下代码无效:@RunWith(SpringJUnit4ClassRunner.class)@RunWith(Parameterized.class)@SpringApplicationConfiguration(classes={ApplicationConfigTest.class})publicclassServiceTest{}但是如何结合使用这两个注解呢? 最佳答案 您可以使用SpringClassRule和SpringMethodRule-Spring提供importorg.junit.C

spring - 跨junit测试类重用spring应用程序上下文

我们有一堆JUnit测试用例(集成测试),它们在逻辑上被分组到不同的测试类中。我们能够为每个测试类加载一次Spring应用程序上下文,并将其重新用于JUnit测试类中的所有测试用例,如http://static.springsource.org/spring/docs/current/spring-framework-reference/html/testing.html中所述但是,我们只是想知道是否有一种方法可以为一堆JUnit测试类只加载一次Spring应用程序上下文。FWIW,我们使用Spring3.0.5、JUnit4.5并使用Maven构建项目。

dart - 怎么解决 找不到: 'dart:ui' error while running integration tests on Flutter

我有一个应用程序,它非常简单,只有一个小部件。它工作正常,但是当我通过调用运行集成测试时:$flutterdrive--target=test_driver/app.dart我收到以下错误:file:///Users/myuser/flutter/packages/flutter_test/lib/src/accessibility.dart:8:8:Error:Notfound:'dart:ui'import'dart:ui'asui;^file:///Users/myuser/flutter/packages/flutter_test/lib/src/binding.dart:8:

gradle - 如何将 Gradle 中的原生 JUnit 5 支持与 Kotlin DSL 结合使用?

我想将内置JUnit5与GradleKotlinDSL一起使用,因为在构建过程中我收到以下警告:WARNING:Thejunit-platform-gradle-pluginisdeprecatedandwillbediscontinuedinJUnitPlatform1.3.PleaseuseGradle'snativesupportforrunningtestsontheJUnitPlatform(requiresGradle4.6orhigher):https://junit.org/junit5/docs/current/user-guide/#running-tests-bu

intellij-idea - 如何让我的 JUnit 测试在我的 Kotlin+Gradle 项目中编译和运行?

我根据thispreviousquestion创建了一个Kotlin+Gradle项目.我添加了两个源文件:src/HelloWorld.ktpackagecom.example.hellofunmain(args:Array){println("Hello,world!")}测试/HelloWorldTest.ktpackagecom.example.helloimportorg.junit.Assertimportorg.junit.TestclassHelloWorldTest{@TestfuntestPasses(){Assert.assertTrue(true)}@Testf

java - Android Studio 3.0 金丝雀 1 : Kotlin tests or Java tests referring to Kotlin classes fail

更新已在此处针对此问题提交了一个错误:https://youtrack.jetbrains.com/issue/KT-17951更新2该错误已在AndroidStudio3.0Canary3中修复原帖我刚开始使用AndroidStudio3.0,我从一开始就启用了kotlin支持。我在我的项目中写了一个非常简单的Kotlin类:dataclassWallet(valcoins:Int){funadd(value:Int):Wallet=Wallet(coins+value)funsubstract(value:Int):Wallet=if(coins>value)Wallet(coin

android - 找不到类 : Empty test suite when running unit tests in Android Studio

我的Android应用有一个测试套件,所有单元测试都运行良好。但是,每当我对我的一个单元测试类(例如,ModelUnitTests)进行一次更改时,在尝试再次运行该类时,我都会收到此消息Processfinishedwithexitcode1Classnotfound:"xxx.xxxxxx.xxx.ModelUnitTests"Emptytestsuite.如果我执行gradleclean然后再次运行类测试,它运行良好(但需要4分钟才能完成......),但是新的更改会再次破坏它。关于如何解决这个问题的任何建议?我不确定我应该发布哪个测试配置。我正在使用单元测试Artifact,我的

AndroidJUnit4.class 已弃用 : How to use androidx. test.ext.junit.runners.AndroidJUnit4?

对于我正在使用的仪器测试@RunWith(AndroidJUnit4.class)来自importandroidx.test.runner.AndroidJUnit4;为了建立我的测试用例。现在这一行被标记为已弃用,并提示使用AndroidJUnit4fromimportandroidx.test.ext.junit.runners.AndroidJUnit4但是,如果我尝试从命名包中导入AndroidJUnit4会收到错误,即无法解析ext。你有什么想法,应该在gradle中包含什么包来解决这个问题? 最佳答案 根据thedocu

unit-testing - Golang : tests and working directory

我正在为我的Go应用程序编写一些单元测试。然而,测试失败,因为它找不到配置文件。通常二进制文件会在conf/*.conf路径下的工作目录中查找配置文件。我认为浏览到有conf/的目录并在其中运行gotest可以解决它,但它仍然报告文件系统找不到路径指定。如何告诉gotest使用某个目录作为工作目录,以便实际执行测试? 最佳答案 您也许可以使用Caller来获取当前测试源文件的路径,如下所示:packagesampleimport("testing""runtime""fmt")funcTestGetFilename(t*testin

java - 将测试文件导入 JUnit 的简单方法

有人可以建议一种简单的方法来获取对文件的引用作为junit测试类中的String/InputStream/File/etc类型对象吗?显然,我可以将文件(在这种情况下为xml)粘贴为一个巨大的字符串或将其作为文件读入,但是有这样特定于Junit的快捷方式吗?publicclassMyTestClass{@Resource(path="something.xml")FilemyTestFile;@TestpublicvoidtoSomeTest(){...}} 最佳答案 你可以试试@Rule注解。以下是文档中的示例:publicsta