草庐IT

monkey-testing

全部标签

testing - 如何在 Flutter 中测试私有(private)函数/方法?

我目前正在开发一个使用bloc架构的应用程序。我的Bloc专门使用流与UI进行通信。因此,除了构造函数之外的所有方法都是私有(private)的(它们以'_'开头)。所以问题是我如何从文本包中的测试类测试bloc的私有(private)方法,使其无法访问其他包的私有(private)方法。 最佳答案 你不能,但你可以将它们公开并且使用@visibleForTesting对其进行注释,以在从不在同一库或test/中的代码访问它们时获得DartAnalyzer警告https://github.com/dart-lang/sdk/blob

unit-testing - Flutter/Dart 在单元测试中等待几秒钟

我正在编写一个计时器应用程序。在单元测试中,如何等待几秒钟来测试我的计时器是否正常工作?//Iwantsomethinglikethis.test("Testingtimer",(){intstartTime=timer.seconds;timer.start();//dosomethingtowaitfor2secondsexpect(timer.seconds,startTime-2);}); 最佳答案 你可以使用awaitFuture.delayed(...)`:test("Testingtimer",()async{ints

testing - Flutter:如何加载文件进行测试

文件可以从相对于dart脚本文件的目录中读取,就像varfile=newFile('./fixture/contacts.json').但是,在IDE中运行的flutter测试无法读取该文件。Loadingasresource(不是,因为我不想在应用程序中捆绑测试数据文件)在测试中也不起作用。什么是flutter中读取文件的好方法(对于命令行测试和IDE测试)?运行fluttertest非常快。但是IntellijIDE内部的测试非常慢,但它可以设置调试断点并单步执行和查看变量。所以这两个测试都非常有用。 最佳答案 刚刚尝试了一下,

dart - 怎么解决 找不到: 'dart:ui' error while running integration tests on Flutter

我有一个应用程序,它非常简单,只有一个小部件。它工作正常,但是当我通过调用运行集成测试时:$flutterdrive--target=test_driver/app.dart我收到以下错误:file:///Users/myuser/flutter/packages/flutter_test/lib/src/accessibility.dart:8:8:Error:Notfound:'dart:ui'import'dart:ui'asui;^file:///Users/myuser/flutter/packages/flutter_test/lib/src/binding.dart:8:

dart - 错误 : Target of URI doesn't exist: 'package:test/test.dart'

自从最新的flutter更新以来,我的测试被打破了。Dart测试框架似乎不再可用:error:TargetofURIdoesn'texist:'package:test/test.dart'. 最佳答案 如果你升级到最近的master,你会发现flutter_test已经移除了它对package:test的依赖。该软件包尚未被删除或重命名,但您现在需要在您的pubspec中专门将其添加到dev_dependencies:dev_dependencies:test:^1.5.1test_api包只是用来统一版本控制,减少flutter

testing - Flutter 测试的代码覆盖率数据如何显示?

我正在开发一个使用AndroidStudio作为我的IDE的Flutter应用程序。我正在尝试编写测试并检查代码覆盖率,但我不知道如何在IDE或任何其他应用程序中查看数据。通过运行fluttertest--coverage,覆盖率报告似乎生成到文件/coverage/lcov.info中。该文件如下所示:SF:lib\data\Customer.g.dartDA:9,2DA:10,2DA:11,2DA:12,2DA:13,2DA:20,0DA:21,0DA:22,0DA:23,0DA:24,0...查看该文件似乎有一个我的项目文件列表,其中包含逐行覆盖数据。有没有办法在AndroidS

unit-testing - Android Studio + Spek 集成

我正在尝试将Spek测试框架添加到我的AndroidStudio项目中。按照说明Here,我最终将以下内容添加到我的模块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(JUnitPla

unit-testing - Kotlin 中的测试无法访问 protected 方法

我要考B类:classB:A{overridefuninit(){//doworkhere}}classA{protectedfuninit(){}//willbecalledbyinternallogic}在Java中调用没有问题:b.init()在测试方法中(测试类与测试对象在同一个包中),但是在Kotlin编译器报错:Cannotaccess'init':itisprotectedin'B'@Testfun`checksinit`(){valb=B()b.init()//assertworkdone}为什么它不起作用?如何解决这个问题(我想避免公开方法)?

unit-testing - 在 kotlin 中模拟同伴对象函数

我正在使用PowerMock和Roboelectric,并希望模拟一个类的伴随对象函数。当我这样做时,我得到一个错误:org.mockito.exceptions.misusing.MissingMethodInvocationException:when()requiresanargumentwhichhastobe'amethodcallonamock'.Forexample:when(mock.getArticles()).thenReturn(articles);我所拥有的基本上是这样的:openclassMockableClassprivateconstructor(cont

unit-testing - 使用 PowerMock 在 Kotlin 中模拟包级函数

我在Kotlin中有一个包含一些包级函数的文件。//Logger.ktfuninfo(tag:String,message:String){...}funerror{....}我正在测试一个调用这个kotlin文件函数的类的函数,我想模拟它们。我知道包级函数就像Java中的静态方法,所以我一直在考虑使用PowerMock。//MyClass:ClassthatcallsLogger.ktfunctionsclassMyClass{funmyFunction(){info("TAG","Helloworld!")}}有什么想法吗? 最佳答案