草庐IT

ParentRunner

全部标签

java - 在单元测试 Controller 时模拟 Spring Validator

在为另一个项目创建的代码编写单元测试事后分析时,我遇到了如何模拟使用initBinder绑定(bind)到Controller的validator的问题?通常我只会考虑确保我的输入有效,并在validator中进行一些额外的调用,但在这种情况下,validator类与通过一些数据源进行检查相结合,这一切都变得一团糟去测试。耦合可以追溯到使用的一些旧的公共(public)库,并且不在我当前修复所有这些库的工作范围内。起初我尝试使用PowerMock和模拟静态方法来模拟validator的外部依赖性,但最终遇到了一个在创建类时需要数据源的类,但没有找到解决该问题的方法.然后我尝试只使用普通

hadoop - 如何在 MRUnit 中使用 avro 参数测试 reducer ?

我正在尝试测试下面的ReducerReducer,AvroKey,NullWritable>出于这些目的,我在测试中使用了下一个代码:CustomReducerreducer=newCustomReducer();reduceDriver=newReduceDriver,AvroKey,NullWritable>();Jobjob=newJob();reduceDriver=ReduceDriver.newReduceDriver(reducer).withConfiguration(job.getConfiguration());reduceDriver.setReducer(red

java - 用MiniDFSCluster对hadoop hdfs写的进行单元测试

我编写了一个写入hadoopHDFS的类。我使用的是1.2.1版的hadoopjar。我想测试这门课。所以基于博客如thisone我写了我的代码:privatevoidcreateSimulatedHdfs(){conf=newConfiguration();//100Kblocksizeconf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY,1024*100);conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY,100);conf.setInt(DFSConfigKeys.DFS_BYTES_PER_CHEC

java - Android : Mockito (2. 0.2-beta) - 无法模拟/监视 final类

我在AndroidInstrumental测试中使用mockito-all,version:'2.0.2-beta'来模拟PowerManager,它是最后一节课,我得到-org.mockito.exceptions.base.MockitoException:Cannotmock/spyclassandroid.os.PowerManagerMockitocannotmock/spyfollowing:-finalclasses-anonymousclasses-primitivetypesatcom.crsardar.handson.android.mockito.ExampleI

android - 使用 SugarORM 和 Robolectric 进行测试

我正在尝试为我的android项目设置测试环境。基本的Robolectric设置已完成。我用这个很好tutorial.如果我在我的Manifest.xml中注释掉SugarORM,所有测试都可以正常工作。但是如果我想将它与SugarORM一起使用,我总是会收到此错误:java.lang.NullPointerExceptionatdalvik.system.DexFile$DFEnum.hasMoreElements(DexFile.java:239)atcom.orm.SugarDb.getDomainClasses(SugarDb.java:37)atcom.orm.SugarDb

java - 如何覆盖 Robolectric 应用程序?

我继承了旧版Android项目并开始添加Robolectric3和JUnit4测试用例。遗憾的是,由于在Robolectric中不起作用的意大利面条代码和框架,目前无法初始化主应用程序类。我想为测试替换我的应用程序类。但是Robolectric在我更新RuntimeEnviroment.application变量之前就崩溃了。有没有办法在Robolectric中禁用list应用程序创建?这是我一直在尝试做的事情:@RunWith(RobolectricGradleTestRunner.class)@Config(constants=BuildConfig.class,sdk=21,ma

java - 如何在 Espresso 中允许繁忙的工作线程

我正在尝试测试应用程序的进度指示器,它在View模型获取数据时显示不确定的进度指示器。为了对此进行测试,我正在模拟返回数据的提供程序并使其阻塞,直到我的测试给出告诉它继续进行。基本设置如下所示:@TestpublicvoidtestProgressIndicator(){injectProvider(mockProvider);startTestActivity();//Themockprovidernowrunsonaworkerthreadandwon'tfinish//untilwetellitto.//Weshouldnowseeaprogressindicator.onVie

android - 在 Android 上使用 PowerMockito 模拟静态方法

我正在尝试stub静态方法,以便我可以对RESTApi接口(interface)进行单元测试。我正在使用...PowerMockito1.5(启用静态模拟)Roboelectric1.2(淘汰android的其余部分)JUnit4.10运行以下代码会出现后续错误有什么办法可以解决这个问题吗?@RunWith(RobolectricTestRunner.class)@PrepareForTest({Api.class})publicclassApiTestextendsTestCase{@RulepublicPowerMockRulerule=newPowerMockRule();...

android - java.lang.IllegalStateException : there must have been some overlap for resourceIdToResName 错误

我正在尝试为我的Android应用程序设置robolectric。我的主要代码有一个子模块和一个外部库,我不使用Maven。关注steps之后设置robolectric项目,当我尝试运行测试时出现以下错误java.lang.IllegalStateException:theremusthavebeensomeoverlapforresourceIdToResName!expected3014butgot3013atorg.robolectric.res.MergedResourceIndex.merge(MergedResourceIndex.java:20)atorg.robolec

java.lang.IllegalStateException : No instrumentation registered! 必须在注册工具下运行

我一直在尝试使用Espresso执行简单的UI测试,但我的所有测试都因相同的异常而失败:java.lang.IllegalStateException:Noinstrumentationregistered!Mustrununderaregisteringinstrumentation这是使用esspresso的初学者指南here.我已经找到了类似的问题,但与我最相关的问题没有得到解答here-我想这是因为他们没有画出全貌,所以这是我的代码。我只会展示一个测试,因为它们都以完全相同的错误失败:build.gradle(Module:app)applyplugin:'com.androi