How to write report test to console

Viewed 530

I'm using gradle-6.5 and when I build my app on my laptop all builds well, but if I try to run the same command on docker, some tests are failed or something is going wrong.
I have an exception like the following:

 Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':test'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:207)
        at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:205)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:186)
...
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///tmp/reports/tests/test/index.html
        at org.gradle.api.tasks.testing.AbstractTestTask.handleTestFailures(AbstractTestTask.java:628)
        at org.gradle.api.tasks.testing.AbstractTestTask.executeTests(AbstractTestTask.java:499)
        at org.gradle.api.tasks.testing.Test.executeTests(Test.java:646)

and I want to know if some way to write a text that placed in an index.html file to console or maybe copy this file to my laptop. For the build my app in the docker I use the following command:

docker build -t myapp .
2 Answers

You want to get the build/reports/tests/test/ directory which contains the test reports (e.g., index.html) onto your local machine. You must use a docker-compose.yml to mirror the the relevant directory:

version: '3.8'
services:
  chat:
    build:
      dockerfile: Dockerfile
      context: .
    command: gradle run
    working_dir: /home/gradle/project
    volumes:
      - type: bind
        source: ./build/reports/tests/test
        target: /home/gradle/project/build/reports/tests/test

There is a simpler way of getting the logs without extra docker-compose file.

First, you should find the id of the stopped container. Type docker ps -a in your terminal to get the list of all containers including the ones that have the status "exited". Find the one that you are interested in and copy the container id.

Second, copy the files from the container to your host. Type docker cp {copied container id}:home/gradle/src/build/reports/tests/test/ ./{location where you want to save your logs on your machine}.

Third, open the location you specified previously, open the index.html file and enjoy full logs output.

Related