【问题标题】:Run Server when Integration Testing with Gradle使用 Gradle 进行集成测试时运行服务器
【发布时间】:2016-06-12 13:32:10
【问题描述】:

我使用 Kryonet 和 Gradle 开发了一个客户端-服务器架构,大致如下结构

  • 父项目 X,包含项目 A 和 B
  • 项目 A(服务器)
  • 项目 B(客户端),包含集成和单元测试类

现在,每当我在项目 B(或项目 X,如果这样更容易的话)上运行目标“集成测试”时,我希望服务器提前启动,这样集成测试就不会失败。

这是我目前在项目 B 的 build.gradle 中得到的 - 但它不运行服务器:

task integrationTest(type: Test) {
    testClassesDir = sourceSets.integrationTest.output.classesDir
    classpath = sourceSets.integrationTest.runtimeClasspath
    outputs.upToDateWhen { false }
}

【问题讨论】:

    标签: testing gradle integration kryonet


    【解决方案1】:

    对此我找到的最简洁的答案是使用 ProcessBuilder 在后台运行服务器,如该问题的答案中所述: How to execute a gradle external task (Exec) in background?

    在你的情况下,我会在父项目 X 中创建一个任务,启动一个单独的 gradle 构建(使用上面的)来运行服务器,然后运行客户端。

    【讨论】:

      猜你喜欢
      • 2015-10-03
      • 1970-01-01
      • 2018-06-11
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 2022-08-20
      • 2013-08-06
      • 2019-03-25
      相关资源
      最近更新 更多