Alternative to JUnit assertions that provides a more insightful log narrative for your tests
Clone or download
dependabot[bot] and rnorth Bump maven-scm-plugin from 1.9.4 to 1.11.1 (#13)
Bumps [maven-scm-plugin](https://github.com/apache/maven-scm) from 1.9.4 to 1.11.1.
<details>
<summary>Commits</summary>

- [`6e3e330`](apache/maven-scm@6e3e330) [maven-release-plugin] prepare release maven-scm-1.11.1
- [`5ec25fd`](apache/maven-scm@5ec25fd) [SCM-912] Unify messages if SCM system command is not available
- [`0b4dbcc`](apache/maven-scm@0b4dbcc) Fix Checkstyle errors
- [`66a260a`](apache/maven-scm@66a260a) [SCM-859] Subversion commands don't work if path or URL contains '@'
- [`184e6fe`](apache/maven-scm@184e6fe) [SCM-911] Skip tests if Git executable is not in PATH
- [`64ab819`](apache/maven-scm@64ab819) [SCM-911] Skip tests if Git executable is not in PATH
- [`148287b`](apache/maven-scm@148287b) [SCM-910] SvnScmProviderRepository#parseUrl(): skip parsing of user info for ...
- [`24115a9`](apache/maven-scm@24115a9) [SCM-908] GitScmProviderRepository#parseUrl(): skip parsing of user info for ...
- [`9f148fa`](apache/maven-scm@9f148fa) [SCM-906] JGit provider tests miss SLF4J binding
- [`92d79ca`](apache/maven-scm@92d79ca) [SCM-905] Tests with checkin rely on global Git config (2)
- Additional commits viewable in [compare view](apache/maven-scm@maven-scm-1.9.4...maven-scm-1.11.1)
</details>
<br />

[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=org.apache.maven.plugins:maven-scm-plugin&package-manager=maven&previous-version=1.9.4&new-version=1.11.1)](https://dependabot.com/compatibility-score.html?dependency-name=org.apache.maven.plugins:maven-scm-plugin&package-manager=maven&previous-version=1.9.4&new-version=1.11.1)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

---

**Note:** This repo was added to Dependabot recently, so you'll receive a maximum of 5 PRs for your first few update runs. Once an update run creates fewer than 5 PRs we'll remove that limit.

You can always request more updates by clicking `Bump now` in your [Dependabot dashboard](https://app.dependabot.com).

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Automerge options (never/patch/minor, and dev/runtime dependencies)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)

Finally, you can contact us by mentioning @dependabot.

</details>
Latest commit 403de69 Oct 8, 2018

README.md

Visible Assertions

Alternative to JUnit assertions that provides a more insightful log narrative for your tests

Screenshot showing example output

Circle CI

Table of Contents

Use Case

Visible Assertions is designed to be used in place of the standard JUnit Assert class, providing an implementation of many of the core assert* methods. Each method takes an additional parameter which developers can use to describe exactly what the assertion is checking.

The key difference is that every assertion is also accompanied by coloured and formatted log output which describes the progress of the tests in a fun, informative way.

This helps with:

  • giving a useful description of which assertions passed/failed during a test run
  • 'comments as code' - your assertions provide a meaningful description of what they're doing, visible to both people looking at the code and those looking at the test output
  • through contextual markers, symbols* and use of colour**, it's quick to spot where tests have gone awry

(* requires unicode support)

(** coloured output requires a terminal that supports ANSI escape codes. If the terminal doesn't support ANSI, output will fall back to monochrome.)

Usage summary

Simple assertions

A simple example:

assertEquals("The sky is blue", Colours.BLUE, theSkyColour);

yields:

    ✔ The sky is blue

unless it isn't:

    ✘ The sky is blue
        'PURPLE' does not equal expected 'BLUE'

Additionally, when something is perhaps equivalent in value but not in type, additional output will provide a hint. This can be useful in cases where a simple type error has crept in to test code, e.g.:

    ✘ The number of sales is returned correctly
        '42' [java.lang.Integer] does not equal expected '42' [java.math.BigInteger]

Other simple assertion methods provided are:

  • assertTrue
  • assertFalse
  • assertNull
  • assertNotNull
  • assertNotEquals
  • assertSame

Hamcrest

You can use Hamcrest matchers too:

assertThat("the colour of the sky", sky.getColour(), is(equalTo(Colours.BLUE)));

yields:

    ✔ the colour of the sky is BLUE

assertThrows

If you want to assert that a block of code definitely does throw a particular class of assertion:

assertThrows("it blows up if the input is out of range", IllegalArgumentException.class, () -> {
    account.withdraw(-1);
});

This will fail if no exception is thrown or if the wrong type of exception is thrown.

General test narrative

While not strictly assertions, Visible Assertions also provides a handful of log-like methods to allow you to describe what's going on in each test:

  • fail(String message): Just fail for a specified reason, which will be shown in red text.
  • pass(String message): Indicate that some external check passed, with a message that will be shown in green.
  • info(String message): Print a message with an 'info' symbol
  • warn(String message): Print a message with a warning symbol, in yellow
  • context(String message): Plots a message and horizontal line across the terminal to demarcate sections of a test

Maven dependency

<dependency>
    <groupId>org.rnorth.visible-assertions</groupId>
    <artifactId>visible-assertions</artifactId>
    <version>2.0.0</version>
</dependency>

Controlling output

Output may be controlled via system properties:

  • visibleassertions.silence: if set to true, assertions will still be enforced but no output will be produced.
  • visibleassertions.silence.passes: if set to true, assertion passes will not be output.
  • visibleassertions.silence.failures: if set to true, assertion failures will not be output.

The library will attempt to detect terminal capabilities to determine whether it is appropriate to use ANSI (coloured) output. The basic logic is:

  • If STDOUT is a TTY, ANSI coloured output will be used. Otherwise, ANSI colour codes will only be output if:
  • running under Maven (latest versions of Maven will strip/preserve as appropriate)
  • running under IntelliJ IDEA

If it is necessary to override this for some reason, the visibleassertions.ansi.enabled may be set:

  • -Dvisibleassertions.ansi.enabled=true: ANSI output will always be produced
  • -Dvisibleassertions.ansi.enabled=false: ANSI output will never be produced

License

See LICENSE.

Attributions

This project is extracted from TestPackage by the same author.

Contributing

  • Star the project on Github and help spread the word :)
  • Post an issue if you find any bugs
  • Contribute improvements or fixes using a Pull Request. If you're going to contribute, thank you! Please just be sure to:
    • discuss with the authors on an issue ticket prior to doing anything big
    • follow the style, naming and structure conventions of the rest of the project
    • make commits atomic and easy to merge
    • verify all tests are passing. Build the project with mvn clean install to do this.

Copyright

Copyright (c) 2015-2017 Richard North.

See AUTHORS for contributors.