Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/guide/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ include::{root-dir}/libs/expectations/src/test/java/builders/dsl/expectations/Ex
<1> Annotate method with `@Test`
<2> Use `evaluate()` method to execute all the assertions

== Source Location Tracking

When your tests fail, Expectations DSL Builder automatically includes source location information in the error messages to help you quickly identify where the failing test data was defined in your code.

[TIP]
====
**Enhanced Error Messages**: When a test fails, the error message will show:

* The template name and values that failed
* The exact source location `(FileName.java:lineNumber)` where the failing data row was created using `is()`, `are()`, or `and()` methods

This makes debugging much easier, especially when you have many data rows or complex test setups.

Example error message:
```
Verification failed for 2 + 3 = 5 with values a=2, b=3, c=6 (ExpectationsTest.java:194)
```

The `(ExpectationsTest.java:194)` part shows exactly which line in your test file created the failing data row.
====

== Using More Dynamic Parameters

You can also define the parameter values using `Stream` or `Iterable` objects. In that case the given method will alter header and `Stream` or `Iterable` to define the data rows.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ Stream<DynamicTest> generateTests(String template, Assertion1<A> verification) {
return DynamicTest.dynamicTest(
title,
() -> {
if (!verification.verify(row.getA())) {
throw new AssertionFailedError("Verification failed for " + title + " with values " + headers.getA() + "=" + row.getA());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + title + " with values " + headers.getA() + "=" + row.getA() + " " + row.getLocation(), throwable);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ Stream<DynamicTest> generateTests(String template, Assertion10<A, B, C, D, E, F,
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI(), row.getJ())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + ", " + headers.getJ() + "=" + row.getJ());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI(), row.getJ());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + ", " + headers.getJ() + "=" + row.getJ() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ Stream<DynamicTest> generateTests(String template, Assertion2<A, B> verification
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + " " + row.getLocation(), throwable);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ Stream<DynamicTest> generateTests(String template, Assertion3<A, B, C> verificat
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + " " + row.getLocation(), throwable);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,17 @@ Stream<DynamicTest> generateTests(String template, Assertion4<A, B, C, D> verifi
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + " " + row.getLocation(), throwable);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,17 @@ Stream<DynamicTest> generateTests(String template, Assertion5<A, B, C, D, E> ver
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,17 @@ Stream<DynamicTest> generateTests(String template, Assertion6<A, B, C, D, E, F>
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,17 @@ Stream<DynamicTest> generateTests(String template, Assertion7<A, B, C, D, E, F,
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,17 @@ Stream<DynamicTest> generateTests(String template, Assertion8<A, B, C, D, E, F,
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,17 @@ Stream<DynamicTest> generateTests(String template, Assertion9<A, B, C, D, E, F,
return DynamicTest.dynamicTest(
finalTitle,
() -> {
if (!verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI())) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI());
boolean verified = false;
Throwable throwable = null;

try {
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI());
} catch (Throwable e) {
throwable = e;
}

if (!verified) {
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + " " + row.getLocation(), throwable);
}
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package builders.dsl.expectations.dsl;

import builders.dsl.expectations.source.SourceLocation;

/**
* Represents a row with one element.
*
Expand All @@ -25,6 +27,7 @@
public class Row1<A> {

private final A a;
private final SourceLocation location;

/**
* Creates a new row with one element.
Expand All @@ -33,6 +36,7 @@ public class Row1<A> {
*/
public Row1(A a) {
this.a = a;
this.location = SourceLocation.createLocationInTheTestClass();
}

/**
Expand All @@ -44,4 +48,13 @@ public A getA() {
return a;
}

/**
* Returns the source location where the row was created.
*
* @return the source location
*/
public SourceLocation getLocation() {
return location;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package builders.dsl.expectations.dsl;

import builders.dsl.expectations.source.SourceLocation;

/**
* Represents a row with ten elements.
*
Expand All @@ -43,6 +45,7 @@ public class Row10<A, B, C, D, E, F, G, H, I, J> {
private final H h;
private final I i;
private final J j;
private final SourceLocation location;

/**
* Creates a new row with ten elements.
Expand All @@ -69,6 +72,7 @@ public Row10(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) {
this.h = h;
this.i = i;
this.j = j;
this.location = SourceLocation.createLocationInTheTestClass();
}

/**
Expand Down Expand Up @@ -161,4 +165,13 @@ public J getJ() {
return j;
}

/**
* Returns the source location where the row was created.
*
* @return the source location
*/
public SourceLocation getLocation() {
return location;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package builders.dsl.expectations.dsl;

import builders.dsl.expectations.source.SourceLocation;

/**
* Represents a row with two elements.
*
Expand All @@ -27,6 +29,7 @@ public class Row2<A, B> {

private final A a;
private final B b;
private final SourceLocation location;

/**
* Creates a new row with two elements.
Expand All @@ -37,6 +40,7 @@ public class Row2<A, B> {
public Row2(A a, B b) {
this.a = a;
this.b = b;
this.location = SourceLocation.createLocationInTheTestClass();
}

/**
Expand All @@ -57,4 +61,13 @@ public B getB() {
return b;
}

/**
* Returns the source location where the row was created.
*
* @return the source location
*/
public SourceLocation getLocation() {
return location;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package builders.dsl.expectations.dsl;

import builders.dsl.expectations.source.SourceLocation;

/**
* Represents a row with three elements.
*
Expand All @@ -29,6 +31,7 @@ public class Row3<A, B, C> {
private final A a;
private final B b;
private final C c;
private final SourceLocation location;

/**
* Creates a new row with three elements.
Expand All @@ -41,6 +44,7 @@ public Row3(A a, B b, C c) {
this.a = a;
this.b = b;
this.c = c;
this.location = SourceLocation.createLocationInTheTestClass();
}

/**
Expand Down Expand Up @@ -70,6 +74,14 @@ public C getC() {
return c;
}

/**
* Returns the source location where the row was created.
*
* @return the source location
*/
public SourceLocation getLocation() {
return location;
}

}

Loading