我一直在努力从 IntelliJ 内部调试 Grails 2.5.0 应用程序。具体来说,我发现很难配置该应用程序,以便
- 功能测试可调试
- 可以运行功能测试
- 该应用程序可以调试
- 该应用程序可以运行
当 (1) 和 (2) 从 IntelliJ(版本 14.1.4)内部启动时。
这是一个玩具 Grails 应用程序 https://github.com/domurtag/multi-col-constraint-bug我正在用来调查这个问题,它有一个功能测试。调试工作的关键似乎是这些 JVM 分叉设置BuildConfig.groovy https://github.com/domurtag/multi-col-constraint-bug/blob/master/grails-app/conf/BuildConfig.groovy#L17L32.
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon: true, jvmArgs: jvmArgs],
// configure settings for the run-app JVM
run : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false, jvmArgs: jvmArgs],
// configure settings for the run-war JVM
war : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
// Include the line below to debug functional tests from IntelliJ. The tests should be launched in Debug mode from IntelliJ
//grails.project.fork = null
调试运行应用程序 (3)
启用分叉后,可以通过从 IntelliJ 内部运行应用程序来调试应用程序,然后从 IDE 启动远程调试器以连接到端口 5005 上的应用程序。JVM 分叉设置可确保应用程序始终在启用远程调试的情况下运行,因此确保通过以下方式启动应用程序running它,而不是调试 it.
调试功能测试(1)
要调试功能测试,您需要包括这条线 https://github.com/domurtag/multi-col-constraint-bug/blob/master/grails-app/conf/BuildConfig.groovy#L32
grails.project.fork = null
这样就可以分叉(并且禁用远程调试)。然后您可以通过 IntelliJ 调试配置启动测试来调试功能测试。
必须根据正在调试的应用程序还是功能测试来包含/注释掉这一行是相当乏味的,所以我正在寻找一个更简单的解决方案。
人们可能认为这可以避免
if (Environment.current == Environment.TEST) {
grails.project.fork = null
}
但由于某种未知的原因,这不起作用。