草庐IT

Viewport-units

全部标签

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

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

flutter - 在 flutter 中使用 TabBarView 获取 'Horizontal viewport was given unbounded height.'

我正在尝试制作个人资料页面,其中用户信息位于顶部。然后在其下方有一个选项卡View,用于不同的View。这是我目前正在使用的代码,当我将TabBarView取出时,它不会出现错误,如果我将TabBarView包装在Expanded错误RenderFlex子项具有非零flex但传入的高度约束是无界的。出现。@overrideWidgetbuild(BuildContextcontext){returnScaffold(appBar:AppBar(title:Text(''),),body:Column(crossAxisAlignment:CrossAxisAlignment.start

flutter - 垂直视口(viewport)出现无界高度错误

这个问题在这里已经有了答案:Verticalviewportwasgivenunboundedheight(23个回答)关闭2年前.@overrideWidgetbuild(BuildContextcontext){returnColumn(children:[newText("Sometext"),ListView()],);}WidgetListView(){returnListView(padding:EdgeInsets.symmetric(vertical:8.0),children:Item(),);}ListItem(){returnlist.map((item)=>It

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}为什么它不起作用?如何解决这个问题(我想避免公开方法)?

function - 如何使用 Kotlin 将函数输出转换为 Unit

我在Kotlin中应该返回Unit的函数遇到问题,但由于使用了另一个返回bool值的函数,存在类型不匹配。这是一个人为的例子:funprintAndReturnTrue(bar:Int):Boolean{println(bar)returntrue}funfoo(bar:Int):Unit=when(bar){0->println("0")else->printAndReturnTrue(bar)}在这里,我实际上并不关心printAndReturnTrue返回bool值的事实。我只想foo执行副作用操作。但是编译器会警告类型不匹配:我的else应该返回一个Unit值。有没有一种将值转

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!")}}有什么想法吗? 最佳答案

kotlin - 类型不匹配推断类型为 Unit 但应为 Void

一个带有字符串和监听器(类似于swift中的闭包)参数的kotlin方法。funtestA(str:String,listner:(lstr:String)->Void){}这样调用它。testA("hello"){lstr->print(lstr)}Error:TypemismatchinferredtypeisUnitbutVoidwasexpected什么是单位??闭包的返回类型是Void。阅读很多其他问题,但可以通过这种简单的方法找到这里发生的事情。 最佳答案 根据Kotlin文档,单元类型对应于Java中的void类型。所

unit-testing - 如何测试在 Kotlin 中调用顶级函数的代码?

我对Kotlin很陌生。我有一个调用顶级函数(进行http调用)的类。我正在尝试为我的类(class)编写单元测试,而无需将其发布到网络上。有没有办法模拟/powermock/拦截从我的类(class)到Kotlin顶级函数的调用?classMyClass{funsomeMethod(){//dosomestuff"http://somedomain.com/some-rest/action".httpGet(asList("someKey"to"someValue")).responseString{(request,response,result)->//someprocessin