Questions tagged [assertj]

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

386 questions
1
vote
2 answers

In Testcase statment gives error after upgrading the springboot version from 2.1.7 to 2.6.4

After updating the Spring Boot version to 2.6.4 I am getting error in the test case while in its old version 2.1.7 working fine @Test fun `Should include id in all outbound requests`() { (authenticationSource as…
Jimmy
  • 995
  • 9
  • 18
1
vote
1 answer

How to verify that nulls are in the end of the list

I need to verify that data is sorted according to rule that all null values are in the end of the list. Is any appropriate method exist for it in assertj? I don't want to write something like - I am looking for first null in the list and then verify…
Ip Man
  • 77
  • 10
1
vote
0 answers

How to get screenshot for each soft assert failure with AssertJ SoftAssertions

I want to achieve below: - CustomSoftAssertJ softly = new CustomSoftAssertJ(); softly.assertThat(actual).isEqualTo(expected); // get screen shot on failure softly.assertThat(actual).isEqualTo(expected); // get screen shot on…
1
vote
0 answers

Await until assertJ asserts true on database update

I am running a test that sends some data to a database and checks it's all been inserted properly. Depending on the machine, this can take varying amounts of time. I am using awaitly/assertj. Is there a way of rerunning the tests up to a maximum…
Sheen
  • 586
  • 10
  • 22
1
vote
1 answer

How to use logger to print messages with assert

I am trying to implement a logger in my repo and I am having some issues with implementing logger with Junit. Sample assertion: logger.info("Asserting the response."); assertThat(response.statusCode()) .withFailMessage("The test…
Bilal
  • 558
  • 8
  • 18
1
vote
1 answer

How to start writing Unit Tests for SpringBoot(The proper way)?

I'm new to the world of unit testing in Spring and with some research I think I'll be using Junit5 with mockito and AssertJ library for the same. I am just starting out and it does look really confusing. 1st Question: Do we write our units first??…
Narupo
  • 39
  • 8
1
vote
1 answer

Creating assertions

So I want to create an assertion class like how AssertJ works. I'm having trouble getting started. public class Assertion { static object assertThis(Object o){} static Integer assertThis(int i){} static String…
rd1346
  • 23
  • 5
1
vote
2 answers

How can I test whether a list is sorted with AssertJ

Given List list = ... I would like to test with AssertJ whether it is sorted. Something like: assertThat(list).isSorted() Is it possible?
user3429660
  • 2,420
  • 4
  • 25
  • 41
1
vote
1 answer

AssertJ Swing enterText() writing wrong symbols

I'm using Swing to create a GUI for my application that has a JSpinner named "spinner". Inside the tests, created using AssertJ Swing I have something like this: import org.assertj.swing.fixture.FrameFixture; import…
ClaudiaR
  • 3,108
  • 2
  • 13
  • 27
1
vote
0 answers

Configure keybord layout before and after for testing with assertj-swing

I am using assertj-swing to test a simple GUI application. When I enter text in a JTextField, I am getting: IllegalArgumentException: Invalid key code '65406' It seems it happens because I am using a german keyboard layout, so to solve this problem…
1
vote
1 answer

AssertJ: How to build custom and nested assertions

I need to compare one PatientDTO dto object with other one PatientModel model object. Both classes are quite similar: class PatientDTO { private String name; private List address; // Constructors, getters and…
Jordi
  • 20,868
  • 39
  • 149
  • 333
1
vote
2 answers

AssertJ dynamically check if Optinal is empty or present

I'm working with OptionalAssert class of AssertJ and I need to implement a JUnit ParameterizedTest that will check for presence or emptiness of an Optional instance in a dynamic way: @ParameterizedTest @MethodSource(/* values */) void…
davioooh
  • 23,742
  • 39
  • 159
  • 250
1
vote
1 answer

How to attach/embed captured screenshots during custom softAssertion into Cucumber Report?

In soft assertion screenshot get captured when softAssertions.assertAll() is called. So to capture screenshots for each soft Assertion failure, created simple CustomAssertion which extends to SoftAssertions and in that override a method name…
DeepakVerma
  • 179
  • 1
  • 3
  • 14
1
vote
1 answer

Use AssertJ in Spring Boot production code

Is it possible to use AssertJ in Spring Boot production code ? I managed to use it in unit test, but 'import static org.assertj.core.api.Assertions.*;' could not be resolved in java file of src/main/java folder even though I tried to fix it by…
1
vote
1 answer

How to check that several fields of an object are not empty with AssertJ?

I have a class with some fields: class User { String name; String id; // other fields } I'm getting a user from the service and want to assert that name and id fields are not empty. The object contains other fields, but those are not needed…
Vitali Plagov
  • 722
  • 1
  • 12
  • 31