Tag: junit

即使使用noarg插件,也没有使用Kotlin的JPA实体的默认构造函数

我开始学习Kotlin,目前版本为1.1.0。 首先,我正在重写我的实体和当前项目中的测试。 我已经读过,你需要实体类的“kotlin-maven-noarg”,以便它生成默认参数少的构造函数,但是我的项目仍然抱怨。 你能告诉我我做错了什么吗? pom.xml中: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> {…} <build> <sourceDirectory>src/main/java</sourceDirectory> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testSourceDirectory>src/test/java</testSourceDirectory> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <version>${kotlin.version}</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>test-compile</id> <phase>test-compile</phase> <goals> <goal>test-compile</goal> </goals> […]

Kotlin为assertThat(foo,instanceOf(Bar.class))

你将如何用Kotlin编写assertThat(foo, instanceOf(Bar.class)) ? 似乎它不喜欢.class 如果可能的话,我想去找一个比assertTrue(foo is Bar)更“精确”的断言

Junit,如何禁用每个测试方法创建Test的新实例

有没有一些方法来禁用Test per @Test的创建新实例?

Android Studio 3.0“JUnit版本3.8或更高版本”

试图遵循这 一点,但没有任何运气。 我正在使用Android studio 3.0和junit 4.12。 Windows 10。 我曾经尝试过: 移动junit依赖项(试过测试编译和实现范围) 删除运行中的测试 – 编辑配置… – 删除Android JUnit和Android应用程序下的所有 我的分级看起来像这样: apply plugin: 'kotlin' dependencies { implementation project(':domain') compile fileTree(include: ['*.jar'], dir: 'libs') testCompileOnly 'junit:junit:4.12' testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version" implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0' testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" testImplementation 'com.nhaarman:mockito-kotlin:1.1.0' testImplementation 'org.amshove.kluent:kluent:1.14' implementation 'com.google.api.client:google-api-client-repackaged-com-google-common-base:1.2.3-alpha' implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' } 我的测试看起来像这样: package ***.roompanel.data; […]

具有多个源集的Gradle下的JUnit 5

我有一个项目,我正在把我想要使用JUnit 5。 我已经在单元测试中正常工作了。 然而,我确实有多个测试源集 – 我还有一个用于验收测试。 我正在努力研究如何让JUnit 5在一个任务中运行src / test中定义的单元测试,并在另一个任务中运行“acceptanceTest”sourceSet中定义的“验收测试”,并位于“src / acceptance”中任务。 我以前有过使用JUnit 4和Cucumber的工作,但JUnit 5插件似乎并不想这样工作。 的build.gradle: buildscript { ext { jackson_version = "2.9.0.pr4" // IntelliJ needs M4 junitJupiter_version = "5.0.0-M4" junitPlatform_version = "1.0.0-M4" kotlin_version = "1.1.3-2" slf4j_version = "1.7.25" spring_version = "4.3.10.RELEASE" springBoot_version = "1.5.4.RELEASE" springBootAdmin_version = "1.5.2" runAcceptance = System.properties['noAcceptance'] == null } repositories […]

Mockito从来没有()不工作,然后rxjava2

我正在测试用Kotlin编写的一段相当简单的代码: o1.updateUser(params) .andThen(o2.reload()) 当updateUser失败时,我预计重装将不会被执行。 但是当使用Mockito 2和jUnit 5进行测试时,就会调用这个模拟。 嘲笑是这样做的: given(o1.updateUser(user)).willReturn(Completable.error(IllegalArgumentException()) given(o2.reload()).willReturn(Completable.complete()) 现在的问题是,代码的行为如预期的,这意味着在这种情况下,o2是从来没有实际调用,但单元测试Mockito声称有一个o1的调用。 测试断言如下所示: verify(o2, never()).reload() 我在这里做错了吗? 有没有解决的办法? 我是不是很了解操作员?

我怎样才能用gradle运行kotlintest测试?

从Intellij开始,kotlintest测试运行得非常好,但是当我尝试用gradle测试任务命令运行它们时,只发现并运行了常规的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 } } } 的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" […]

Android w / Kotlin纯java-Junit的NoClassDefFoundError解决方法不起作用

存储库,可靠地重现错误:爆炸/ bug-kotlin-junit 我的Android应用程序由一个应用程序模块和4个库模块组成。 我的测试是用纯Java编写的。 不碰Kotlin代码的测试运行得很好,但是当我运行使用( MyKotlinObj::methodRef )或者在一个类( new MyKotlinObj() )中的测试时,我的测试将会失败,如下所示: java.lang.NoClassDefFoundError: com/explod/api/UserCreated at com.explod.api.Bug.initUserCreated_shouldNotTriggerNoClassDefFoundError(Bug.java:19) 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:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51) […]

IntelliJ + JUnit 5(木星)

我的build.gradle有: testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0' 使用http://junit.org/junit5/docs/current/user-guide/中的标准示例 import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class FirstJUnit5Tests { @Test void myFirstTest() { assertEquals(2, 1 + 1); } } 当我尝试在IntelliJ 2017.2.3中作为JUnit测试运行时,我得到: objc[32347]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x10f5be4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10f6864e0). One of the two will be used. Which one is undefined. Sep 11, 2017 12:39:04 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: […]

Gradle + JUnit + Android数据绑定

设置: Android Studio 3b6,Kotlin(1.1.4-3),Gradle(插件3.0.0-beta6),JUnit4,数据绑定 问题:使用./gradlew测试运行我的JUnit测试时,除了测试我的视图模型的测试之外,所有测试都成功。 视图模型是使用Google数据绑定库实现的 。 java.lang.SecurityException: class "android.databinding.BaseObservable"'s signer information does not match signer information of other classes in the same package at java.lang.ClassLoader.checkCerts(ClassLoader.java:898) at java.lang.ClassLoader.preDefineClass(ClassLoader.java:668) 在Android Studio中运行测试时没有问题。 任何想法如何解决这个问题?