File: TruthAssertExpected.md

package info (click to toggle)
error-prone-java 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,076 kB
  • sloc: java: 171,398; xml: 1,459; sh: 34; makefile: 7
file content (27 lines) | stat: -rw-r--r-- 666 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Arguments to a fluent [Truth][truth] assertion appear to be reversed based on
the argument names.

```java
  int expected = 1;
  assertThat(expected).isEqualTo(codeUnderTest());
```

This is problematic as the quality of Truth's error message depends on the
argument order. If `codeUnderTest()` returns `2`, this code will output:

```
expected: 2
but was : 1
```

Which will likely make debugging the problem harder. Truth assertions should
follow the opposite order to JUnit assertions. Compare:

```java
  assertThat(actual).isEqualTo(expected);
  assertEquals(expected, actual);
```

See https://truth.dev/faq#order for more details.

[truth]: https://truth.dev