Как получить логи из теста через Базель? - PullRequest
0 голосов
/ 11 февраля 2020

Я использую bazel для создания и запуска тестов для моего проекта.

Я хочу получить более полное представление о том, как выполняются мои тесты. Я хочу, чтобы в моем приложении java отображался вывод, записанный регистратором.

Я попытался добавить параметр -s для запуска моих тестов, например: bazel test -s //myproject:integration-test

и это дает мне больше информации о том, как вызывается тест:

remote: Resolving deltas: 100% (101/101), completed with 18 local objects.
To github.com:Canva/canva.git
$ bazel test -s //myproject:integration-tests
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
/nix/store/qsmyc0p2z1z3m06ch37hz49m0hz2c270-bazel-rc
INFO: Invocation ID: 2d17fb35-c72b-4152-bf14-2805027c6c01
INFO: Analyzed target //myproject:integration-tests (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
SUBCOMMAND: # //myproject:integration-tests [action 'Testing //myproject:integration-tests', configuration: cd8c76baa0169ef7c8b826ed0feb93200dd87a70639fd99286b8801aa9226239]
(cd /private/var/tmp/_bazel_antkong/cf188c7bd288685357ff03fcbb494066/execroot/com_canva_canva && \
  exec env - \
    CI='' \
    DISPLAY=:1 \
    EXPERIMENTAL_SPLIT_XML_GENERATION=1 \
    FLAVOR=local \
    JAVA_RUNFILES=bazel-out/darwin-fastbuild/bin/myproject/integration-tests.runfiles \
    PATH=/nix/store/6ajpp69s5lf5krrdzy3mw1fs22vg1fqq-user-environment/bin \
    PYTHON_RUNFILES=bazel-out/darwin-fastbuild/bin/myproject/integration-tests.runfiles \
    RUNFILES_DIR=bazel-out/darwin-fastbuild/bin/myproject/integration-tests.runfiles \
    RUN_UNDER_RUNFILES=1 \
    TEST_BINARY=myproject/integration-tests \
    TEST_INFRASTRUCTURE_FAILURE_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.infrastructure_failure \
    TEST_LOGSPLITTER_OUTPUT_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.raw_splitlogs/test.splitlogs \
    TEST_PREMATURE_EXIT_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.exited_prematurely \
    TEST_SIZE=large \
    TEST_SRCDIR=bazel-out/darwin-fastbuild/bin/myproject/integration-tests.runfiles \
    TEST_TARGET=//myproject:integration-tests \
    TEST_TIMEOUT=900 \
    TEST_TMPDIR=_tmp/73bce5ef685ff9d5d824b9a0b736db87 \
    TEST_UNDECLARED_OUTPUTS_ANNOTATIONS=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.outputs_manifest/ANNOTATIONS \
    TEST_UNDECLARED_OUTPUTS_ANNOTATIONS_DIR=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.outputs_manifest \
    TEST_UNDECLARED_OUTPUTS_DIR=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.outputs \
    TEST_UNDECLARED_OUTPUTS_MANIFEST=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.outputs_manifest/MANIFEST \
    TEST_UNDECLARED_OUTPUTS_ZIP=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.outputs/outputs.zip \
    TEST_UNUSED_RUNFILES_LOG_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.unused_runfiles_log \
    TEST_WARNINGS_OUTPUT_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.warnings \
    TEST_WORKSPACE=com_canva_canva \
    TZ=UTC \
    XAUTHORITY=/dev/null \
    XML_OUTPUT_FILE=bazel-out/darwin-fastbuild/testlogs/myproject/integration-tests/test.xml \
  external/bazel_tools/tools/test/test-setup.sh myproject/integration-tests)
Aspect @mypy_integration//:mypy.bzl%mypy_aspect of //myproject:integration-tests up-to-date (nothing to build)
INFO: Elapsed time: 6.692s, Critical Path: 5.34s
INFO: 1 process: 1 processwrapper-sandbox.
INFO: Build completed successfully, 2 total actions
//myproject:integration-tests                                      PASSED in 5.1s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 2 total actions

Однако на самом деле это не то, что мне нужно. Я хочу, чтобы вывод был зарегистрирован через вызовы в логгере в java код:

  private static final Logger logger = LoggerFactory.getLogger(
      MyProject.class);

  ...

  logger.info('It is executed')

Можно ли использовать какой-либо переключатель, чтобы bazel мог включить ведение журнала?

1 Ответ

4 голосов
/ 11 февраля 2020

Когда вы запускаете тест bazel, используйте флаг --test_output. См. docs .

bazel test --test_output=errors //...

. Выше будет показан тестовый вывод в случае ошибки, но вы также можете запросить его, чтобы показать вывод независимо от неудачи:

bazel test --test_output=all //...
...