Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the log messages from test via bazel?

Tags:

java

bazel

I am using bazel to build and run tests for my project.

I want to get more insight into how my tests are running. I want to be able to see the output captured by the logger in my java app.

I have tried adding -s parameter to start my tests, like so: bazel test -s //myproject:integration-test

and it gives me more info regarding how the test is invoked:

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

However it is actually not what I am after. I want to able to see the output logged via calls to a logger in java code:

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

  ...

  logger.info('It is executed')

Is there any switch I can use so bazel can turn on the logging?

like image 983
Anthony Kong Avatar asked Feb 11 '20 09:02

Anthony Kong


People also ask

What does Bazel test do?

Bazel build process When running a build or a test, Bazel does the following: Loads the BUILD files relevant to the target. Analyzes the inputs and their dependencies, applies the specified build rules, and produces an action graph. Executes the build actions on the inputs until the final build outputs are produced.

How do I run a test with Bazel?

The test can be run with bazel test //mypkg:myrules_test . Aside from the initial load() statements, there are two main parts to the file: The tests themselves, each of which consists of 1) an analysis-time implementation function for the testing rule, 2) a declaration of the testing rule via analysistest.

How do I run Bazel commands?

To run Bazel, go to your base workspace directory or any of its subdirectories and type bazel . % bazel help [Bazel release bazel-<version>] Usage: bazel <command> <options> ... Available commands: analyze-profile Analyzes build profile data.

Where does Bazel build output?

The Bazel user's build state is located beneath outputRoot/_bazel_$USER . This is called the outputUserRoot directory. Beneath the outputUserRoot directory there is an install directory, and in it is an installBase directory whose name is the MD5 hash of the Bazel installation manifest.


1 Answers

When you run bazel test, use the --test_output flag. See docs.

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

The above will show the test output in the event of an error, but you can also request it to show output regardless of success failure:

bazel test --test_output=all //...
like image 190
user2515975 Avatar answered Oct 23 '22 08:10

user2515975