使用JUnit运行时,Intellij IDEA不会停止在Kotlin断点处
当试图执行一些Kotlin代码,同时也使用JUnit时,Intellij IDEA将执行代码直到结束,而不是停在断点处。
演示:
class Tester { @Test fun shouldBreakpoint() { //Line where threads should suspend: println("Should Suspend Here") //Breakpoint added to this line println("Shouldn't run this code unless I release above breakpoint") } }
当点击“Debug Tester”或“Debug shouldBreakpoint”时,不会有断点。
控制台输出两个打印行,没有停在断点处。 如果使用Java编写相同的代码,则调试器将工作:
public class Testerino { @Test public void shouldBreakpoint() { System.out.println("Should Suspend Here"); //Breakpoint added to this line System.out.println("Shouldn't run this code unless I release above breakpoint"); } }
在Kotlin main
function上运行时,它也能正常工作:
fun main(args: Array) { println("Should Suspend Here") //Breakpoint added to this line println("Shouldn't run this code unless I release above breakpoint") }
这是在一个Android项目上运行的,build.gradle(app)文件是:
apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion 27 buildToolsVersion "27.0.3" defaultConfig { applicationId "me.kerooker.visualhonk" minSdkVersion 19 targetSdkVersion 27 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true } buildTypes { release { minifyEnabled false shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt') } debug { debuggable true minifyEnabled false // set this to false proguardFiles getDefaultProguardFile('proguard-android.txt') } } } configurations.all { resolutionStrategy { forcedModules = [ "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version", "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" ] } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:27.+' compile 'com.android.support.constraint:constraint-layout:+' compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" testCompile 'io.kotlintest:kotlintest:2.0.7' testCompile 'junit:junit:4.12' } repositories { mavenCentral() }
Intellij能够在断点处正确识别和停止什么?
- 我如何使IntelliJ重构 – >重命名参数只重命名它的本地版本? (Kotlin)
- Kotlin和Gradle没有Maven中央?
- IntelliJ:Kotlin错误导致鼠标闪烁和代码中的错误
- 如何在gradle中插入想法插件为Kotlin生成适当的项目配置?
- 在intellij 16中创建Android应用时,Gradle同步失败
- 即使使用noarg插件,也没有使用Kotlin的JPA实体的默认构造函数
- Intellij IDEA不显示Kotlin文件中的Android资源的可用建议
- 如何获得IntelliJ IDEA代码完成作为Kotlin顶级函数导入静态Java方法?
- Kotlin类文件不能在IntelliJ for JUnit中运行