Tag: 单元测试

结果一样,但是测试用例没有通过单元测试

我只是碰了单元测试,今天遇到了一个很奇怪的问题,我用assertThat来判断两个对象是否相等,有一个测试用例不能通过,当我测试这个对象的时候: sealed class SummaryViewState : MviViewState { /** * 默认显示曲线图和标签汇总状态(首次进入页面) */ data class SummaryDataViewState( val points: List<Pair<Int, Float>>, // 曲线图点val months: List<Pair<String, Date>>, // 曲线图月份val values: List<String>, // 曲线图数值文本val selectedIndex: Int, // 曲线图选中月份索引val summaryItemList: List<SummaryListItem> // 当月标签汇总列表) : SummaryViewState() /** * 切换月份时标签汇总状态*/ data class SummaryGroupingTagViewState( val summaryItemList: List<SummaryListItem> // 当月标签汇总列表) : SummaryViewState() } 但是看结果是一样的: java.lang.AssertionError: […]

测试类中的java.util.logging.Logger

我想为我的类使用java.util.logging.Logger运行一个测试 import java.util.logging.Logger; public class TestLogging { final Logger logger = Logger.getLogger("Test"); public void f1() { logger.entering(getClass().getName(), "f1"); logger.info("f1"); logger.fine("f1"); logger.finer("f1"); logger.finest("f1"); logger.exiting(getClass().getName(), "f1"); } } 所以我设置了一个测试类来检查记录器在测试类时是否产生输出 import org.junit.Before import org.junit.Test import java.util.logging.Level import java.util.logging.Logger class TestLogger { @Before fun setupLogger() { Logger.getLogger("Test").level = Level.FINEST } @Test fun test() { TestLogging().f1() } } 但是当我运行它时,我只看到下面的输出,就好像关卡设置为默认。 TestLogger […]

什么是测试(0)在这个片段kotlinlang.org?

我在这里试图解决KotlinKoans页面中的“运行”问题 这是我的实现 package runs fun runs(a: IntArray): Int { var numberOfRuns = 1; for (index in 0..a.size-2) { if (a[index+1] != a[index]) numberOfRuns++ } return numberOfRuns } 这里是针对实现运行的测试套件 class Tests { @Test fun testRuns1() { test(0) } @Test fun testRuns2() { test(1, 1) } @Test fun testRuns3() { test(3, 1, 2, 3) } @Test fun […]

模拟属性设置器

我想在我的测试中嘲弄一个属性设置者,但我怎么也找不到任何东西。 这是我迄今为止所尝试的: interface Foo { var property: Int } @RunWith(MockitoJUnitRunner::class) class TestClass { @Mock private val fooMock: Foo = mock() private var temp = 0 @Before fun setup() { whenever(fooMock.property).then { invocation -> if (invocation.arguments.isEmpty()) { // this part works fine return@then 15 } else { // this never gets called temp = invocation.getArgument(0) null […]

如何在模拟类中调用特定的lambda?

我有下一个案例的参数: @Test fun lostClick() { //setup parameters val func0 : (Unit) -> Unit = { println("fun0")} val func1 : (String) -> Unit = { println("fun1")} val func2 : (Int) -> Unit = { println("fun2")} whenever(deviceInteractor.reserveBadCaseDevice( //equals `when` eq(workerId), eq(DeviceCondition.LOST), eq(func0), eq(func1), eq(func2))).then({ func0.invoke(Unit) }) presenter.lostClick() //view reaction verify(viewState).showLoad(true) // verify(viewState).setButtonGiveEnabled(true) // if func0 called this […]

如何测试包装在`runOnUiThread`中的代码?

我有一个函数调用runOnUiThread如下 fun myFunction(myObject: MyClass, view: MyView) { // Do something view.getActivity().runOnUiThread { myObject.myObjectFunction() } } 我想单元测试myFunction以确保myObject已经调用myObjectFunction 。 但是鉴于它是在runOnUiThread包装的,我无法得到它。 我怎么能单元测试,以确保runOnUiThread内的runOnUiThread被调用?

Android系统。 Mockito使用真实的对象而不是模拟

所以,我只是写简单的测试。 问题是测试运行器运行真正的“仓库”类代码,而不是模拟代码…你有什么想法,为什么我可以得到这个例外? 测试课 class SingInFacebookPresenterTest { @Mock private lateinit var view: SignInFacebookContract.View @Mock private lateinit var repository: Repository @Captor private lateinit var callback: ArgumentCaptor<RepositoryCallback.FacebookLoginImp> private lateinit var presenter: SingInFacebookPresenter private val serverToken = "token" @Before fun init() { MockitoAnnotations.initMocks(this) presenter = SingInFacebookPresenter(MockContext(), repository, view) } @Test fun facebook_login_success() { //Given val token = "token" val […]

如何在多项目中使用Spek来设置Jacoco?

我想要测量雅科科在儿童项目之一的model项目中的覆盖面。 然而,在test任务之后, jacocoTestReport任务被跳过。 test : :model:compileKotlin UP-TO-DATE :model:compileJava UP-TO-DATE :model:copyMainKotlinClasses UP-TO-DATE :model:processResources UP-TO-DATE :model:classes UP-TO-DATE :model:compileTestKotlin UP-TO-DATE :model:compileTestJava UP-TO-DATE :model:copyTestKotlinClasses UP-TO-DATE :model:processTestResources UP-TO-DATE :model:testClasses UP-TO-DATE 3 10, 2017 8:17:48 org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines Discovered TestEngines with IDs: [spek] :model:junitPlatformTest Test run finished after 113 ms [ 4 containers found ] [ 0 containers skipped ] [ 4 […]

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 { […]

ReferenceError:ok没有在Kotlin Javascript的QUnitAsserter.assertTrue中定义

Kotlin版本1.0.x-1.1.0支持使用QUnit的单元测试,但是当我加载测试时,它会引发这个异常: ReferenceError: ok is not defined at QUnitAsserter.assertTrue_4mavae$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:50:5) at assertTrue (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:93:27) at QUnitAsserter.assertTrue_o10pc4$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:47:5) at QUnitAsserter.Asserter.assertEquals_lzc6tz$ (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:182:10) at assertEquals (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/lib/kotlin-test-js.js:108:20) at AppTest.myFirstTest (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/app_test.js:17:5) at Object.<anonymous> (file:///D:/neoranga/Mis%20documentos/GitHub/FibonacciCounter/app/build/classes/test/app_test.js:29:21) 这是我的测试课: import org.junit.Test import kotlin.test.assertEquals class AppTest { @Test fun myFirstTest() { assertEquals(1, 1, "Test in test folder works") } } 这是加载测试的html代码: <!doctype html> <html lang="en"> <head> <meta […]