运行 来自 IntelliJ 的 Corda 流测试时出错

Error when running Corda flow tests from IntelliJ

当我从 IntelliJ 运行 Corda 流测试时,测试失败并出现以下错误:

QUASAR WARNING: Quasar Java Agent isn't running. If you're using another instrumentation method you can ignore this message; otherwise, please refer to the Getting Started section in the Quasar documentation.

java.lang.IllegalStateException: Missing the '-javaagent' JVM argument. Make sure you run the tests with the Quasar java agent attached to your JVM. See https://docs.corda.net/troubleshooting.html - 'Fiber classes not instrumented' for more details.

我该如何解决这个问题?

Corda 流在 运行 之前需要使用 Quasar 进行检测,以便它们可以在执行中暂停。

要在 IntelliJ 中实现这一点,您需要:

  • 为您的测试创建 运行 配置
  • 打开 运行 配置并将 VM 选项更改为 -ea -javaagent:PATH-TO-QUASAR-JAR
    • 在 CorDapp 示例和模板中,quasar.jar 位于 lib/quasar.jar,因此您可以使用 -ea -javaagent:../lib/quasar.jar

或者,您可以编辑默认的 JUnit 运行 配置以默认使用 Quasar javaagent,避免每次为 运行 选择新测试时都必须这样做。

这是一个基本错误,如果你没有设置 Quasar,你需要 select 你的测试 -> 转到 Intellij 顶部栏 -> 运行 -> 编辑配置和然后在 VM 选项中像这张照片一样设置:

来自模板自述文件

We recommend editing your IntelliJ preferences so that you use the Gradle runner - this means that the quasar utils plugin will make sure that some flags (like -javaagent - see below) are set for you.

To switch to using the Gradle runner:

Navigate to Build, Execution, Deployment -> Build Tools -> Gradle -> Runner (or search for runner) Windows: this is in "Settings" MacOS: this is in "Preferences" Set "Delegate IDE build/run actions to gradle" to true Set "Run test using:" to "Gradle Test Runner" If you would prefer to use the built in IntelliJ JUnit test runner, you can run gradlew installQuasar which will copy your quasar JAR file to the lib directory. You will then need to specify -javaagent:lib/quasar.jar and set the run directory to the project root directory for each test.