Tag: kotlintest

使用SpringJUnit4ClassRunner的KotlinTest的BehaviorSpec“No runnable methods”

我写了下面的测试: @RunWith(SpringJUnit4ClassRunner::class) class KotlinTest : BehaviorSpec() { init { given("a stack") { val stack = Stack<String>() `when`("an item is pushed") { stack.push("kotlin") then("the stack should not be empty") { stack.isEmpty() shouldBe true } } `when`("the stack is popped") { stack.pop() then("it should be empty") { stack.isEmpty() shouldBe false } } } } } 当我尝试运行它时,我有以下错误: java.lang.Exception: […]

我怎样才能用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" […]

Kotlintest样品缺少进口声明

在kotlintest站点上“最终”的样本不起作用。 需要进口证明? 需要依赖build.gradle? 编程Kotlin书籍上的示例代码的同样的问题。 Quote:KotlinTest提供了最终的mixin,它给你最终的方法,将重复测试代码,直到它通过,或达到超时。 这是非确定性代码的完美选择。 例如: import io.kotlintest.specs.ShouldSpec class MyTests : ShouldSpec() { init { should("do something") { eventually(5.seconds) { // code here that should complete in 5 seconds but takes an indetermistic amount of time. } } }

在kotlin单元测试中如何赋值lateinit var

@RunWith(MockitoJUnitRunner::class) class RoundingTest { lateinit var rounding: (Double) -> Double @Before fun initValues(){ rounding(17.25) } @Test fun checkRounding() { rounding(17.25) var rounding = MyRoundingClass.roundValue(Myobject); Assert.assertEquals(17.23, rounding) } } object MyRoundingClass{ fun roundValue(myObject: MyObject): (Double) -> Double { return when (myObject.isrouding?.needed) { ROUND_DOWN -> { value -> roundDown(BigDecimal.valueOf(value)) } else -> // no rounding { value […]

Kotlin,如何测试(int)数组

我想找一个好的简明的方式来测试intarray 起初我试了一下 mFaces[0].mIndices shouldBe intArrayOf(0, 1, 2) mIndices在哪里 var mIndices: IntArray = IntArray(0) 但失败。 Intellij也建议我用Array来覆盖equals() 然后我想尝试这样的事情 mFaces[0].mIndices.all { it. == index } shouldBe true 但它看起来像没有办法检索all{..}的索引或是这样的 var p = 0 mFaces[0].mIndices.all { it == p++ } shouldBe true 唯一的可能性?

是否有相当于AssertJ库的Kotlin?

我正在将一些测试从Java转换到Kotlin。 对于Java测试,我使用AssertJ库,这个库非常强大,并且拥有丰富的断言。 我的问题是,对于Kotlin测试,我不能使用AssertJ和Kotlin JUnit( org.jetbrains.kotlin:kotlin-test-junit )具有非常有限的一组断言。 有没有Kotlin相当于AssertJ或更好的方式断言? 我找到了Kluent库,但是我仍然不确定这是否是最好的库。