Tag: kotlintest

是否有相当于AssertJ库的Kotlin?

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

如何让kotlintest与Spring一起工作?

我试图使用kotlintest与spring(不是春季启动,只是标准的春季测试)。 我觉得这很难做到。 任何指针,我在做什么错? 我也是Kotlin的新手,所以我可能不会做正确的事情。 这是我迄今为止所尝试的: import io.kotlintest.matchers.shouldBe import io.kotlintest.specs.BehaviorSpec import org.junit.ClassRule import org.junit.Rule import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.test.context.ContextConfiguration import org.springframework.test.context.junit4.rules.SpringClassRule import org.springframework.test.context.junit4.rules.SpringMethodRule open class SomeBean { open fun sayHello() = “Hello” } @Configuration open class TestConfig { @Bean open fun someBean(): SomeBean = SomeBean() } @ContextConfiguration(classes = arrayOf(TestConfig::class)) open class MyTests(var someBean: SomeBean) : […]

有一个kotlintest项目的样本结构

我目前正在玩Kotlin测试框架https://github.com/kotlintest/kotlintest 。 我想知道是否有一个预期的方式来组织项目,我的意思是,像一个基础项目,我可以开始立足。

如何在每次测试之前使用kotlin-test框架初始化variables

我试图find一种方法来设置每个测试前的variables。 就像Junit中的@Before方法一样。 通过kotlin-test的文档,我发现我可以使用interceptTestCase()接口。 但不幸的是,下面的代码会触发exception: kotlin.UninitializedPropertyAccessException: lateinit property text has not been initialized class KotlinTest: StringSpec() { lateinit var text:String init { “I hope variable is be initialized before each test” { text shouldEqual “ABC” } “I hope variable is be initialized before each test 2” { text shouldEqual “ABC” } } override fun interceptTestCase(context: TestCaseContext, […]

在kotlin测试

我是kotlin开发kotlin 。 在我的应用程序中,我想编写测试用例,但是我无法使用它。 Src / test / kotlin文件夹没有被创建 gradle这个 android { compileSdkVersion 27 defaultConfig { applicationId “in.getparking.getparkingattendant” minSdkVersion 23 targetSdkVersion 27 versionCode 1 versionName “1.0” multiDexEnabled true testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner” } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile(‘proguard-android.txt’), ‘proguard-rules.pro’ } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } sourceSets { test.java.srcDirs += ‘src/test/kotlin’ androidTest.java.srcDirs += […]

如何通过interceptTestCase来更改KotlinTest中的测试对象属性

我正在尝试使用interceptTestCase方法为KotlinTest中的测试用例设置属性,如下所示: class MyTest : ShouldSpec() { private val items = mutableListOf<String>() private var thing = 123 override fun interceptTestCase(context: TestCaseContext, test: () -> Unit) { items.add("foo") thing = 456 println("Before test ${items.size} and ${thing}") test() println("After test ${items.size} and ${thing}") } init { should("not work like this") { println("During test ${items.size} and ${thing}") } } […]

如何在kotlintest 2.x(interceptSpec)中正确初始化共享资源

我试图在单元测试之前的beforeAll / afterAll类型设置中做一个标准,但是有一些问题。 这似乎是interceptSpec功能是我想要的,文件明确提到这是很好的清理数据库资源,但我找不到一个很好的例子。 代码如下: class MyTest : StringSpec() { lateinit var foo: String override fun interceptSpec(context: Spec, spec: () -> Unit) { foo = "foo" println("before spec – $foo") spec() println("after spec – $foo") } init { "some test" { println("inside test – $foo") } } } 这导致下面的输出: before spec – foo kotlin.UninitializedPropertyAccessException: lateinit […]

是否有可能检索lambda表达式中的字符串?

使用字符串规范编写测试: class stl : StringSpec() { init { "triangle.stl" { … } } } 是否有可能检索lambda表达式中的"triangle.stl" ?

应该和应该在KotlinTest中有什么区别?

这是一个使用KotlinTest 1.3.5的测试代码。 val expect = 0.1 val actual: Double = getSomeDoubleValue() actual shouldBe expect 这个警告是在代码运行时打印的。 [WARN]比较双打时考虑使用宽容,例如:a shouldBe b plusOrMinus c 在这种情况下,我不想使用plusOrMinus 。 所以,我修复了代码 val expect = 0.1 val actual: Double = getSomeDoubleValue() actual shouldBe exactly(expect) 现在,没有任何警告。 不过,我想知道shouldBe和shouldBe exactly的区别。 它是什么?

如何在每次测试之前使用kotlin-test框架初始化变量

我试图找到一种方法来设置每个测试前的变量。 就像Junit中的@Before方法一样。 通过kotlin-test的文档,我发现我可以使用interceptTestCase()接口。 但不幸的是,下面的代码会触发异常: kotlin.UninitializedPropertyAccessException: lateinit property text has not been initialized class KotlinTest: StringSpec() { lateinit var text:String init { "I hope variable is be initialized before each test" { text shouldEqual "ABC" } "I hope variable is be initialized before each test 2" { text shouldEqual "ABC" } } override fun interceptTestCase(context: TestCaseContext, […]