大佬教程收集整理的这篇文章主要介绍了Android Studio 3.0 Canary 1:Kotlin测试或引用Kotlin类的Java测试失败,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
解决方法(目前):
将其放入您的(应用程序级)build.gradle:
task copyTESTClasses(type: copy) {
from "build/tmp/kotlin-classes/deBUGUnitTest"
into "build/intermediates/classes/deBUG"
}
@H_301_6@
然后在“启动之前”自下而下修改测试JUnit Run / DeBUG配置,在其中有“ Gradle-aware
make”,
您可能需要更改/添加更多目录管道,具体取决于您的构建类型。查找那些奇怪位置的方法是通过在项目树中粗略搜索相关的.class文件。 更新 已针对此问题提交了一个错误:https : 更新2 该错误已在Android studio 3.0 Canary 3中修复 原始帖子 我刚刚开始使用Android studio 3.0,从一开始就启用了kotlin支持。我在项目中编写了一个非常简单的Kotlin类: 现在我想测试该类,首先我在Kotlin中编写了一个本地运行的unittest(测试目录): 它编译并运行,但显示错误消息: 因此,我重新编写了Java中的测试: 但是该测试也失败了-这次找不到Kotlin类“钱包”: 我想知道我是否缺少某些东西&Hellip;运行Java测试,该测试不引用Kotlin类,但是仅成功完成Java类。 我的项目build.gradle文件是默认文件: 我特定于模块的build.gradle的依赖项:+@H_301_6@另一部分,选择
gradle
task@H_301_6@,选择
build.gradle@H_301_6@它所在的项目文件,然后键入
copyTESTClasses@H_301_6@。单击此处获取不同测试框架的屏幕截图,但是管道的工作原理相同。
解决方法
//youtrack.jetbrains.com/issue/KT-17951data class Wallet(val coins: int) {
fun add(value: int): Wallet = Wallet(coins + value)
fun substract(value: int): Wallet = if (coins > value) Wallet(coins + value) else throw InsufficientFundsException()
}
class WalletTestKotlin {
@Throws(Exception::class)
@Test
fun add() {
Assert.assertEquals(22,Wallet(20).add(2).coins.toLong())
Assert.assertNotEquals(5,Wallet(2).add(13).coins.toLong())
}
}
public class WalletTest {
@Throws(exceptionClasses = Exception.class)
@Test
public void add() {
Assert.assertEquals(22,new Wallet(20).add(2).getCoins());
Assert.assertNotEquals(5,new Wallet(2).add(13).getCoins());
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
maven { url 'https://maven.google.com' }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
dependencies {
compile fileTree(dir: 'libs',include: ['*.jar'])
//Kotlin support
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
//TesTing libraries
androidTESTCompile('com.android.support.test.espresso:espresso-core:2.2.2',{
exclude group: 'com.android.support',module: 'support-Annotations'
})
TESTCompile 'junit:junit:4.12'
TESTCompile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
TESTCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
以上是大佬教程为你收集整理的Android Studio 3.0 Canary 1:Kotlin测试或引用Kotlin类的Java测试失败全部内容,希望文章能够帮你解决Android Studio 3.0 Canary 1:Kotlin测试或引用Kotlin类的Java测试失败所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。