无法在Docker容器中使用Bazel运行JUnit5测试

时间:2020-03-19 13:10:14

标签: docker kotlin junit bazel

我有一个带有Bazel的Kotlin项目,其中运行了一些JUnit5测试:

bazel run //my_service:tests

这是输出:

Test run finished after 1195 ms
[         3 containers found      ]
[         0 containers skipped    ]
[         3 containers started    ]
[         0 containers aborted    ]
[         3 containers successful ]
[         0 containers failed     ]
[         5 tests found           ]
[         0 tests skipped         ]
[         5 tests started         ]
[         0 tests aborted         ]
[         5 tests successful      ]
[         0 tests failed          ]

5个测试成功。到现在为止还挺好。但是当测试在Bazel Docker容器中运行时,我得到以下输出:

 Test run finished after 79 ms
[         1 containers found      ]
[         0 containers skipped    ]
[         1 containers started    ]
[         0 containers aborted    ]
[         1 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]

如您所见,没有找到测试。为什么?

我使用以下命令在容器内运行测试:

$ docker run -it -v $(pwd):/my_service --entrypoint "" l.gcr.io/google/bazel:2.2.0 /bin/bash
$ cd my_service
$ bazel run //my_service:tests

我在本地和Docker映像中都使用了Bazel 2.2.0。为什么我没有得到相同的输出?

1 个答案:

答案 0 :(得分:3)

我找到了解决方案。真是奇怪。我使用的是register_toolchains规则,而不是kt_register_toolchain。愚蠢的我。