Automating your tests

Running the whole test suite with a single command and reading the result: build tool, report (run, failures, errors, skipped), exit code, running a single class or test.

  • 22 cards
  • 3 topics
  • Free

The outline, topic by topic

Each topic is weighted the way the exam weighs it.

  1. Concepts
  2. Questions
  3. Sort and link

A few cards from the deck

  • Test suite: what is it?

    Show the answer

    A set of tests run together, in a single launch, to judge the state of a project.

    A test run by hand is quickly forgotten; a suite launched by a command gives a global verdict, that of the whole project.

  • What is the exit code of mvn test when a test fails?

    • A non-zero value: the build has failed
    • 0, since Maven itself ran correctly to the end
    • The number of tests that passed
    • 0 if at least half the tests pass
    Show the answer

    A non-zero value: the build has failed

    A single failing test is enough for Maven to end with a non-zero code (1 in practice): that code is what lets a script or an integration server stop the delivery.

  • With Maven, the … command compiles the project then runs the whole test suite.

    Show the answer

    With Maven, the mvn test command compiles the project then runs the whole test suite.

    Maven reads the pom.xml file and finds the test classes on its own, in src/test/java.

  • Build tool: what is it?

    Show the answer

    A program that compiles the project, runs the tests and produces the deliverable, from a description file: Maven and Gradle are two for Java.

    The mvn test command compiles the code, then runs the tests: nobody needs to know the list of classes.

  • The end of the report says Tests run: 5, Failures: 1, Errors: 0, Skipped: 1. How many tests passed?

    • 4
    • 3
    • 5
    • 2
    Show the answer

    3

    The 5 tests include the skipped one: 5 − 1 failure − 0 errors − 1 skipped = 3 passed. 4 would forget the skipped test, and 5 would be the total run.