Tag: spek

测试环境配置:Android + JUnit 5 + Mockito + Spek + Kotlin

我很难配置基于JUnit Jupiter(5)的测试环境。 我有两个不同的错误: WARNING: TestEngine with ID ‘spek’ failed to discover tests org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name… Exception in thread “main” java.lang.NoSuchMethodError: org.junit.platform.launcher.Launcher.execute(Lorg/junit/platform/launcher/LauncherDiscoveryRequest;)V at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:61)… 配置如下。 主build.gradle : apply plugin: ‘org.junit.platform.gradle.plugin’ buildscript { ext.kotlin_version = ‘1.1.4-3’ repositories { google() jcenter() } dependencies { classpath ‘com.android.tools.build:gradle:3.0.0-beta5’ classpath “org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version” classpath “org.junit.platform:junit-platform-gradle-plugin:1.0.0” classpath “de.mannodermaus.gradle.plugins:android-junit5:1.0.0” } } […]

无法在Ktor应用程序中运行启动程序Spek测试

我使用IntellJ版本2017.2.5构建Ktor应用程序。 我也想用Spek来测试应用程序。 我从一个非常简单的文件开始, import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.jetbrains.spek.api.dsl.on import kotlin.test.assertEquals class SampleSpec : Spek({ given(“some context”) { on(“executing some action”) { it(“should pass”) { assertEquals(2, 2) } } } }) 当我右键点击运行测试,我得到以下错误: Feb 08, 2018 2:50:32 PM org.junit.platform.launcher.core.DefaultLauncher handleThrowable WARNING: TestEngine with ID ‘spek’ failed to discover tests java.lang.NoClassDefFoundError: org/junit/platform/engine/discovery/ClasspathSelector at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:48) at […]

Android Studio + Spek集成

我正在尝试将Spek测试框架添加到我的Android Studio项目中。 按照说明在这里 ,我结束了以下添加到我的模块build.gradle : testCompile ‘org.jetbrains.spek:spek-api:1.1.5’ testCompile ‘junit:junit:4.12’ testCompile “org.junit.platform:junit-platform-runner:1.0.0” testRuntimeOnly ‘org.jetbrains.spek:spek-junit-platform-engine:1.1.5’ 然后我用@RunWith(JUnitPlatform::class)注释了我的测试。 但是,当我尝试运行测试,我得到: org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath org.junit.platform.commons.util.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath 任何想法我错过了什么?

在beforeEachTest和afterEachTest之前不要运行方法kotlin spek android

我试图在Android上使用Spek框架编写一个测试。 但是我很困惑。 根据代码,演示者必须在beforeEachTest方法中初始化。 并且必须在afterEachTest之后的方法中清除条件。 但是当我运行这个测试时,它在mPresenter !!。setPass(PASSWORD,PASSWORD)行中失败了。 但是如果你取消它前面的两条线,那么测试就会成功。 可能是什么问题呢? 在此先感谢您的答案 object ResetPasswordPresenterTestKotlin : Spek({ include(RxSchedulersOverrideSpek) val PASSWORD = “123456aZ”; var mView = mock{} var mMockDataManager = mock{} var mToken = mock{} var mPresenter : ResetPasswordPresenter ?= null beforeEachTest { print(“beforeEachTest”) mPresenter = ResetPasswordPresenter(mMockDataManager) mPresenter!!.attachView(mView) } afterEachTest { print(“afterEachTest”) mPresenter!!.detachView() reset(mView) } describe(“Reset password is succesful”) { […]

用kotlin spek和kluent运行测试

试图让科特林工作,但遇到一些问题。 我有最简单的测试: object TestSpec : Spek({ describe(“A greeter”) { it(“should fail”) { “hello” shouldEqual “somethingelse” } } }) 它不起作用。 我已经尝试了以下变化: object TestSpec : Spek({ describe(“A greeter”) { it(“should fail”) { “hello” shouldEqual “somethingelse” } } }) 这个测试是绿色的,显然不应该是。 object TestSpec : Spek({ describe(“A greeter”) { on(“something”) { it(“should fail”) { “hello” shouldEqual “hellosdf” } } } […]

java.lang.ClassNotFoundException:com.intellij.junit5.JUnit5IdeaTestRunner在kotlin中使用spek

我在kotlin测试中使用spek非常新。 使用spek时,在logcat上得到以下错误。 我不是为什么我得到这个 java.lang.ClassNotFoundException: com.intellij.junit5.JUnit5IdeaTestRunner at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at com.intellij.rt.execution.junit.JUnitStarter.getAgentClass(JUnitStarter.java:252) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) 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 com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131) 我有以下依赖gradle文件 testImplementation 'junit:junit:4.12' testImplementation 'org.jetbrains.spek:spek-api:1.1.0-beta3' testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.0-beta3' testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M3' 测试文件 import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.junit.Assert.assertEquals import org.junit.platform.runner.JUnitPlatform […]

为什么这个Spek的行动不运行?

当我运行这个示例代码时,“on”动作中的所有代码都不会在Android Studio中运行。 你知道为什么吗? 什么不见​​了? import org.jetbrains.spek.api.Spek import org.jetbrains.spek.api.dsl.describe import org.jetbrains.spek.api.dsl.given import org.jetbrains.spek.api.dsl.it import org.jetbrains.spek.api.dsl.on @RunWith(JUnitPlatform::class) class SpekTest : Spek({ val x = 2 val y = 3 given("x = $x and y = $y") { val sum = x + y on ("why does this not run?") { it("should be that x + y = […]

用kotlin spek和kluent运行测试

试图让科特林工作,但遇到一些问题。 我有最简单的测试: object TestSpec : Spek({ describe("A greeter") { it("should fail") { "hello" shouldEqual "somethingelse" } } }) 它不起作用。 我已经尝试了以下变化: object TestSpec : Spek({ describe("A greeter") { it("should fail") { "hello" shouldEqual "somethingelse" } } }) 这个测试是绿色的,显然不应该是。 object TestSpec : Spek({ describe("A greeter") { on("something") { it("should fail") { "hello" shouldEqual "hellosdf" } } } […]

使用spek进行测试,并为基类共享一些基本测试用例

我使用Spek作为测试框架,并且在共享基类的一些测试步骤时遇到麻烦。 我有一个抽象基类和两个派生类。 abstract class Base { abstract fun send() } class Foo : Base() { override fun send() {} fun anotherFunction() { } } class Bar : Base() { override fun send() {} fun differentFunction() { } } 现在我的问题是:如何为这些分类创建Speks,但只在基本spek中定义一次send()的测试? 我的第一个方法是使用SubjectSpek class BaseSpek : SubjectSpek<Base>({ subject { // ??? Can't instantiate Base because it is abstract […]

Kolin Spek框架崩溃w / Gradle

当spek试图找到测试时,我正在崩溃。 我已经尝试了许多不同的版本和示例配置。 我正在从命令行运行。 Gradle 4.0,mac osx。 任何帮助将不胜感激! 这是错误: WARNING: TestEngine with ID 'spek' failed to discover tests java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.findAllClassesInClasspathRoot(Ljava/nio/file/Path;Ljava/util/function/Predicate;Ljava/util/function/Predicate;)Ljava/util/List; at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:66) at org.jetbrains.spek.engine.SpekTestEngine.discover(SpekTestEngine.kt:50) at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130) at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90) at org.junit.platform.launcher.Launcher.execute(Launcher.java:96) at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:65) at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57) at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33) at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57) at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:85) at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:75) at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:48) at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:40) 这里是我目前的build.gradle: buildscript { repositories { jcenter() maven { […]