I made a simple test :
Person p = new Person();
p.setFirstName("Stéphane");
p.setLastName("Traumat");
assertThat(p)
.extracting("firstName", "lastName")
.contains(tuple("Stéphane", "Traumat"));
And I get a strange result :…
In a test class using AssertJ, I have code similar to the following:
public void someTest() {
assertThat(getNames()).has(sameNamesAs(getExpectedNames()));
assertThat(getNames()).doesNotHave(sameNamesAs(getOtherNames()));
}
private…
Are there any examples on how to test single Component or JComponent with AssertJ?
Getting started guide shows strange example to test entire application with main class, which is no granulated enough. I am expecting to test custom components…
I am migrating from JUnit 5 and Hamcrest Assertions to AssertJ and I can't figure out the right method for extracting the actual exception from the executable. Here is a JUnit/Hamcrest example:
var result = assertThrows(MyException.class, () ->…
I want to learn how to write JUnit tests and I fail completely.
This is my test:
@Test
public void testGetAllCustomers() {
// given
List customerList = new ArrayList();
customerList.add(c1);
…
Currently I have a test which tries to check a particular exception which looks like this:
assertThatExceptionOfType(DataIntegrityViolationException.class).isThrownBy(
() -> xrepo.save(abc))
…
With Assertj, I can use anyMatch to test if a collection has at least one element matching a predicate, e.g.
var list = List.of("abc", "xyz")
assertThat(list).anyMatch(element -> element.endsWith("xyz"));
But how do I test if a collection has…
The project uses TestNg, Java11, Spring test
I am writing testNG tests for API
I have a java object that has this kind of stucture:
class Object1
private Object2 o2;
private List o3;
Where Object2 is not only composed of primitive…
The Javadoc gives this example for the matches method:
assertThat(player).matches(p -> p.isRookie());
And indeed, when I define a dummy class Player, the above statement compiles ok. However, when I define a class that derives from Exception, then…
I've stumbled on an issue where AssertJ generates the following code in one of the assertion classes:
public S hasItems(interface ItemInterface... items)
This of course doesn't compile.
An example code that causes the problem is as follows:
…
Our gui unit-tests with Assertj Swing 3.9.2 occasionally fail in a difficult to reproduce way. Sometimes the entire test suite is green, sometimes some of the test cases fail. We are using two different machines with Ubuntu 18.04 LTS and GNOME and…
Is there a way to log all assertions, not just failing ones?
I wonder whether AssertJ provides an interface to access the details of the assertion (WritableAssertionInfo) and the result of the assertion? Is there any way to hook into the assertion…
I have a List of Optionals, like List> optionals and I like to use assertj on it to assert several things.
But I fail to do this properly - I only find examples on a single Optional.
Of course I can do all checks by myself…
Similar to some other Questions, I find IntelliJ mysteriously refuses to recognize AssertJ library. I am asking again as (a) I have tried the various suggestions, and (b) I have a very simple example anyone can try themselves.
In IntelliJ 2018 and…
Background:
We have a regression test suite that tests the generation of some large xml files by comparing them field-by-field to the corresponding baseline files.
This is implemented using a junit4 parameterized test running the test for each file…