Questions tagged [assertj]

AssertJ provides a set of strongly-typed assertions to use for unit testing (either with JUnit or TestNG).

386 questions
5
votes
1 answer

Using QuarkusTestExtension in combination with another JUnit extension leads to exception

Is it possible to use the QuarkusTestExtension from Quarkus in combination with the SoftAssertionsExtension from AssertJ? I would like to run a Quarkus test which implicitly calls softAssertions.assertAll() after a test which uses AssertJ's soft…
Matthias T
  • 1,230
  • 2
  • 10
  • 24
5
votes
3 answers

Comparing two objects with "special" assertions for certain fields with AssertJ

Given the following class... public class UserAccount { private Long id; private String email; private String activationCode; private Date createDate; } ... I need to compare the actual object with an expected object using AssertJ. However…
Robert Strauch
  • 12,055
  • 24
  • 120
  • 192
5
votes
0 answers

How to fix AssertJ Swing tests that are passing locally but failing in a CI server?

My GUI unit-tests with Assertj Swing (version 3.17.0) all pass locally, but sometimes they fail in a CI server. If i retry long enough, eventually the test suite becomes green. I'm having a hard time figuring out how to fix these tests. I am using…
John Doe
  • 141
  • 10
5
votes
1 answer

Getting package org.assertj.core.api does not exist even though I am specifying in my pom, version 3.6.2 while using JDK 1.8

I am having problem with Eclipse using Maven. I am getting package org.assertj.core.api does not exist even though I am specifying it in my pom.xml, as version 3.6.2 while using JDK 1.8. How to overcome it ? mvn clean install is failing. Failed to…
PraNuta
  • 629
  • 3
  • 12
  • 33
5
votes
2 answers

AssertJ solution for Mockito.verify

Browsing through the API of AssertJ, I didn't seem to come across anything that covers the behaviour of that of Mockito.verify. Right now my assertions are all using the AssertJ fluent API, and then there's the Mockito.verify which is kind of…
Yannick Thibos
  • 93
  • 2
  • 11
5
votes
1 answer

Test that a array contains elements with JUnit and AssertJ

I have followings Unit Test with JUnit 4.12 and AssertJ 3.11.0 and having interesting results. helloTest is green but worldTest is red. @Test public void helloTest() { Object[] array = new Object[2]; String[] firstElement = new…
Quang Nguyen
  • 354
  • 1
  • 5
  • 20
5
votes
1 answer

usingComparatorForType in assertj does not seem to apply to properties of objects that are properties of the object

I want to test equality of two objects but have a certain discretion about the precision of double values that are present on some nested properties of them. usingComparatorForType seems to be an appropriate solution but it doesn't appear to work if…
Lorcan O'Neill
  • 3,303
  • 1
  • 25
  • 24
5
votes
1 answer

Assert that method does not throw an exception with AssertJ 1.x soft assertions

I would like to test that a particular method can handle a bunch of strings without an exception. Therefore, I would like to use AssertJ's soft assertions, something like: SoftAssertion softly = new SoftAssertion(); for (String s : strings) { …
beatngu13
  • 7,201
  • 6
  • 37
  • 66
5
votes
1 answer

How to get started: testing Java Swing GUI with AssertJ Swing

While developing a Java desktop application with Swing, I encountered the need to test the UI directly, and not just the underlying controller/model classes via unit tests. This answer (on "What is the best testing tool for Swing-based…
Carsten
  • 2,047
  • 1
  • 21
  • 46
5
votes
2 answers

Assertj verify that a field of each items in a collection is always null

I'm looking for a solution to check that each items in a collection have the field expectedNullField null. The following doesn't work: assertThat(aCollection).extracting("expectedNullField").isNull(); Note that the following works as…
pierrefevrier
  • 1,570
  • 4
  • 22
  • 33
4
votes
1 answer

Ignoring only embedded member in AssertJ

I have two classes to test with JUnit/Mockito: public class ClassA { private int sk; // getters and setters } public class ClassB { private int sk; private List lista; // getters and setters } Then in my test…
ps0604
  • 1,227
  • 23
  • 133
  • 330
4
votes
1 answer

AssertJ: `ignoringFields` is not ignoring all the provided fields?

I want to compare two objects using org.assertj.core.api.Assertions.assertThat from version 3.14.0: assertThat(getActual()) .usingRecursiveComparison() .ignoringFields("customer", "orders", "\$hashCode",…
Mulgard
  • 9,877
  • 34
  • 129
  • 232
4
votes
2 answers

Verify that assertions have been called in Assertj

I'm reading through test classes that use Assertj to verify results. Occasionally, I've spotted an assertThat without assertions. assertThat(object.getField()); Is it possible to identify these classes somewhere in the development cycle? My first…
TomVW
  • 1,510
  • 13
  • 26
4
votes
1 answer

Assert list contains exactly one element satisfying condition

In my JUnit test I want to assert that a list contains exactly one element satisfying a given condition (there can be many elements in the list, but only one should satisfy the condition). I wrote the code below, but I was wondering if it's possible…
Eric Lilja
  • 3,323
  • 4
  • 18
  • 15
4
votes
2 answers

AssertJ comparing double values

I would like to compare double values with AssertJ. I dont catch why my test is failing. @Test public void testInterestToQuote() { double result = BasicCalculator.accumulationFactorByYearsAndInterest(years, interest) …
Michael Hegner
  • 5,555
  • 9
  • 38
  • 64