java–Kotlin androidTest:测试跑完了.空的测试套件

java–Kotlin androidTest:测试跑完了.空的测试套件,第1张

概述我正在尝试将我的测试从java转换为kotlin.简单的单元测试已成功翻译,如下所示:classBindingUtilsTest{@Test@Throws(Exception::class)funtestConvertBooleanToVisibility_visible(){assertEquals(BindingUtils.convertBooleanToVisibility(true),View.VISIBLE)

我正在尝试将我的测试从java转换为kotlin.

简单的单元测试已成功翻译,如下所示:

class BindingUtilsTest {  @Test @Throws(Exception::class)  fun testConvertBooleanToVisibility_visible() {    assertEquals(BindingUtils.convertBooleanToVisibility(true), VIEw.VISIBLE)  }}

但是当我试图运行androIDTest时,它失败并显示消息:“没有找到测试”和

Test running started
Tests ran to completion.

Empty test suite.

代码工作得很好,在java时.相关代码:

build.gradle部分:

apply plugin: "com.androID.application"apply plugin: "com.neenbedankt.androID-apt"// for testsapply plugin: 'kotlin-androID'// defaultConfigtestInstrumentationRunner "androID.support.test.runner.AndroIDJUnitRunner"sourceSets {    test.java.srcDirs += 'src/test/kotlin' // tests are there    androIDTest.java.srcDirs += 'src/androIDTest/kotlin' // and there}// unit teststestApt "com.Google.dagger:dagger-compiler:${daggerVer}"// kotlintestCompile "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVer}"testCompile "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVer}"// androID testsandroIDTestApt "com.Google.dagger:dagger-compiler:${daggerVer}"// kotlinandroIDTestCompile "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVer}"androIDTestCompile "org.jetbrains.kotlin:kotlin-test-junit:${kotlinVer}"

简单测试:

@RunWith(AndroIDJUnit4::class) class MainDrawerActivityTest {  private val mQuestions = InstrumentationRegistry.getTargetContext().applicationContext as Questions  private val mTestComponentRule = TestComponentRule<Questions, AppComponentTest>(mQuestions,      DaggerAppComponentTest.builder().appModuleTest(AppModuleTest(mQuestions)).build(),      { obj, component -> obj.setAppComponent(component) }, // set test component      { objectToClear -> objectToClear.setAppComponent(null) }) // clear test component  private val mActivityTestRule = ActivityTestRule(      MainDrawerActivity::class.java, false, false)  // TestComponentRule needs to go first to make sure the Dagger TestComponent is set  // in the Application before any Activity is launched.  @Rule @JvmFIEld val mRuleChain: TestRule = RuleChain.outerRule(mTestComponentRule).around(mActivityTestRule)  private var mActivity: MainDrawerActivity? = null  @Before @Throws(Exception::class)  fun setUp() {    mActivityTestRule.launchActivity(null)    mActivity = mActivityTestRule.activity  }  @Test @Throws(Exception::class)  fun testOnCreate() {    val size = mActivity!!.supportFragmentManager.fragments.size    // check if fragment instantly added    assertEquals(size.tolong(), 1)  }}

测试组件在Kotlin中:

// Empty because extends ApplicationComponent@Singleton @Component(modules = arrayOf(    AppModuleTest::class)) interface AppComponentTest : AppComponent

测试模块也在Kotlin中:

@Module class AppModuleTest(private val mApp: Questions) /*: AppModule*/ {  @ProvIDes fun provIDeApp(): Questions {    return mApp  }}

我甚至没有看到,DaggerAppComponentTest是构建的.

为什么我使用apt代替kapt进行测试?

因为我有一个错误,我不能混合apt和kapt在一个项目中.我试图切换到kapt,并得到了数十亿的错误.

据我所知,kapt处理kotlin文件并使用它们人们生成kotlin代码?而对于apt:java文件,java代码.怎么混合呢?如何解决这个问题呢?

接受的解决方案有效.在此之前,我为Kotlin回归了kapt.用kaptAndroIDTest和kaptTest.

解决方法:

更改

@Rule @JvmFIEld val mRuleChain: TestRule = RuleChain.outerRule(mTestComponentRule).around(mActivityTestRule)

@get:Rule @JvmFIEld var mRuleChain: TestRule = RuleChain.outerRule(mTestComponentRule).around(mActivityTestRule)

如果它不起作用,则表示mRuleChain为null,检查Dagger提供的对象.

总结

以上是内存溢出为你收集整理的java – Kotlin androidTest:测试跑完了.空的测试套件全部内容,希望文章能够帮你解决java – Kotlin androidTest:测试跑完了.空的测试套件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1118362.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存