Skip to content

Commit

Permalink
Doc review
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertuya committed Aug 14, 2024
1 parent a4e2158 commit 5158a92
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
![Status](https://github.com/javiertuya/visual-assert/actions/workflows/test.yml/badge.svg)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.javiertuya/visual-assert)](https://search.maven.org/artifact/io.github.javiertuya/visual-assert)
[![Maven Central](https://img.shields.io/maven-central/v/io.github.javiertuya/visual-assert)](https://central.sonatype.com/artifact/io.github.javiertuya/visual-assert)
[![Nuget](https://img.shields.io/nuget/v/VisualAssert)](https://www.nuget.org/packages/VisualAssert/)

# visual-assert
Expand All @@ -9,7 +9,7 @@ Useful for comparing large strings or files.
Available on Java and .NET platforms.

- From Java include the `visual-assert` dependency as indicated in the
[Maven Central Repository](https://search.maven.org/artifact/io.github.javiertuya/visual-assert)
[Maven Central Repository](https://central.sonatype.com/artifact/io.github.javiertuya/visual-assert)
- From .NET include the `VisualAssert` package in you project as indicated in
[NuGet](https://www.nuget.org/packages/VisualAssert/)

Expand All @@ -26,7 +26,9 @@ This will produce an html file in the `target` directory that highlights the dif

![diff-example](docs/diff-file-example.png "Diff example")

The assert statement is overloaded to specify an additional message and the name of the differences file if required:
The assert statement is overloaded to specify an additional message and the name of the differences file
(when the diff file name is not specified, a file `diff-n.html` is automatically generated, where `n` is an
unique sequence number):

```java
va.assertEquals(String expected, String actual, String message)
Expand Down Expand Up @@ -59,12 +61,13 @@ but record the assertion message and allow to continue the test and check other

### Using soft assertions

Class `SoftVisualAssert` implements this type of assertions:
Class `SoftVisualAssert` implements this type of soft assertions:
- After a number of calls to `assertEquals()`, calling `assertAll()` will throw the exception
if at least one previous assertion failed. The message aggregates the messages of all failed assertions.
- If the soft assert instance is shared by more than one test, `assertClear()` must be called
before each sequence of assertions to reset the stored messages.
- In addition to `assertEquals` a `fail` assertion is provided.
- In addition to `assertEquals` a `fail` assertion is provided (the fail message is included
as the actual value compared with an empty expected value).

Example:

Expand Down Expand Up @@ -95,7 +98,7 @@ These methods follow a fluent style, so as, they can be concatenated in a single
- `setNormalizeEol(boolean normalizeEol)`: If set to true, the compared strings are normalized to linux line-endings by removing all CR characters.
- `setSoftDifferences(boolean useSoftDifferences)`: By default (hard), differences in whitespaces are rendered as whitespace html entities and therefore, always visible in the html ouput.
If set to true (soft), some whitespace differences may be hidden from the html output.
- `setBrightColors(boolean useBrightColors)`: By default differences are highlighted with pale red and green colors,
- `setBrightColors(boolean useBrightColors)`: By default, differences are highlighted with pale red and green colors,
if set to true the colors are brighter to easily locate small differences.
- `setDiffFileQualifier(String value)`: When assertions do not specify a diff file name, adds the indicated string to
the autogenerated diff file name.
Expand All @@ -110,15 +113,17 @@ If set to true (soft), some whitespace differences may be hidden from the html o
(e.g. when run multiple modules, each in a different GitHub Actions job,
set the variable GITHUB_JOB in each module).
Note: Jobs that run in a matrix strategy share the same job name.
In this case the workflow should define and environment variable
In this case the workflow should define an environment variable
to differentiate each matrix job.
- `setUseLocalAbsolutePath(boolean useLocalAbsolutePath)`: If set to true, the link with the differences file will include a file url with the absolute path to the file,
useful when running tests from a development environment that allows links in the assertion messages (e.g. MS Visual Studio).
- `setShowExpectedAndActual(boolean showExpectedAndActual)`: If set to true, the assert message will include the whole content of the exepcted and actual strings that are compared.

The `SoftVisualAssert` instances have an additional method to customize:
- `setCallStackLength(int length)`:
Sets the number of call stack items that are shown for each failed assertion (default 1)
Sets the number of call stack items that are shown for each failed assertion (default 1).
Use a value higher than 1 when the method that actually does the assert is not the test method
that should appear in the stack trace to locate the location of the failure.

## Publish from a CI environment

Expand All @@ -138,3 +143,9 @@ To create an artifact including the files with differences using GitHub Actions,
name: Diff files
path: target/*.html
```
When generating consolidated reports from multiple runs
(e.g. JUnit html reports), the failed tests display the name of the diff files,
but the files must be browsed separately.
To link the diff files directly from the test report, the Github Action https://github.com/javiertuya/junit-report-action
has different options to both generate the reports and reprocess them to include the links to the diff files.

0 comments on commit 5158a92

Please sign in to comment.