问题标签 [spek]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
281 浏览

kotlin - 使用 spek 进行测试并共享一些基类的基本测试用例

我使用 Spek 作为测试框架,在共享基类的一些测试步骤时遇到了麻烦。

我有一个抽象基类和两个派生类。

现在我的问题是:如何为那些分类创建 Spek,但只send()在基础 spek 中定义一次测试?

我的第一种方法是使用SubjectSpek

我的第二种方法是使用继承:

看来我的方法都不起作用。任何建议如何解决这个问题?我是否应该提请 Spek-Author 关注 Spek 未来版本中可能发生的变化?

0 投票
1 回答
123 浏览

kotlin - Spek access to Internal Visibility Kotlin Classes

I've put together a Maven-based project that uses Spek in the Junit 4 Runner for testing.

I configured the project in Codacy and got a useful suggestion to either document my public classes or reduce their visibility (great).

I've found that the Kotlin compiler seems to regard the tests as existing in a different module, which makes it very difficult to do effective unit testing given my project layout. The tests will not compile if the visibility of classes or interfaces are reduced to internal.

Please suggest a mechanism to fix this. Is it just not possible to use internal visibility modifier in this situation? Is there a useful compiler configuration or Spek configuration that can overcome the issue? I think the suggestion is indeed correct; I do not wish to document the classes because they are internal and may change in the future or the documentation is simply not worth the effort.

0 投票
1 回答
369 浏览

kotlin - 如何在 Kotlin Spek 测试中组织多个协程和期望块?

it我写了一个失败的 Spek 测试,因为我对涉及多个协程和函数 的执行顺序做出了错误的假设:

我期望abcd被打印,但acbd实际上被打印了。

我应该如何编写这个测试,以便它可以按预期的顺序进行视觉读取和执行?

0 投票
2 回答
1831 浏览

unit-testing - Android Studio + Spek 集成

我正在尝试将 Spek 测试框架添加到我的 Android Studio 项目中。按照此处的说明,我最终将以下内容添加到我的模块中build.gradle

然后我用@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

知道我错过了什么吗?

0 投票
1 回答
768 浏览

intellij-idea - 无法在 Ktor 应用程序中运行 starter Spek 测试

我使用 IntellJ 版本 2017.2.5 来构建 Ktor 应用程序。我还想使用 Spek 来测试应用程序。我从一个非常简单的开始,取自文档:

当我右键单击运行测试时,出现以下错误:

对于冗长的 build.gradle 感到抱歉,但这里是:

知道问题出在哪里吗?

0 投票
1 回答
677 浏览

android - 如何在 Android MVP Clean Architecture 中测试注入存储库的 sharedpreference

我在数据存储中测试 sharedpreference 时遇到了问题。在实际的数据存储中,我实现了三个参数,其中包括 sharedpreference。

在这种情况下,我想存储价值并获得该价值。在这里嘲讽无济于事。

模拟不能传播实际值,这将被代码使用。在第二部分。

这个数据存储看起来像

}

实际上我想从这个领域获得价值serviceLocation。任何人都有办法为此做一些测试?,非常欢迎任何建议。

谢谢!

0 投票
1 回答
3083 浏览

ktor - Ktor:使用 JUnit 测试类的 Spek/KotlinTest 测试 REST 端点

我有一个简单的 hello world Ktor 应用程序:

使用 JUnit 测试类,我可以为它编写测试,如其文档中所述;如下:

但是,我想在 Spek 或 KotlinTest 中进行单元测试,无需 JUnit 的帮助,类似于我在 ScalaTest/Play 中进行的方式;以更具声明性的方式:

  1. 在测试期间向路由(即/)发送 FakeRequest。
  2. 获取页面内容,并检查字符串“hello”。

问题是我可以在 KotlinTest 或 Spek 中以更具声明性的方式编写上述测试吗?

0 投票
1 回答
530 浏览

testing - kotlin:如何从 Spek 类继承以具有通用夹具

我想为我的测试有一个通用的夹具:

现在我想使用该规范:

但由于无参数BaseSpek构造函数,我得到了编译错误。实现我需要的正确方法是什么?

0 投票
1 回答
1124 浏览

java - “未解决的参考:” testCompile 错误

目前,我正在Unresolved reference: spek接受:Unresolved reference: testtestCompile / testRuntime

但是,当我用 切换它们时compile / runtime,我可以成功运行测试!

这是我的 spek 测试:

有人可以帮我调试吗?

谢谢

0 投票
1 回答
221 浏览

kotlin - Spek - 变量未在测试中初始化

以下代码无法编译:

如何解决这个问题?我可以为变量分配什么以消除警告?