instancio: Instancio 6.1 lab (selectors, settings, seeds, records/sealed/generics, JUnit 6 extension, failing-seed capture)
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b4VQVEJWetTT1dYzyJ
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
// Instancio.create(Person.class) -- no seed pinned, so values differ on every run
|
||||
id = <uuid> (non-null: true)
|
||||
name = <4 chars>
|
||||
email = <10 chars> (a random string, NOT an e-mail address)
|
||||
homeAddress non-null: true
|
||||
billingAddress non-null: true
|
||||
orders.size() = 3 (default collection size is 2..6)
|
||||
@@ -0,0 +1,7 @@
|
||||
// 200 people from Instancio.of(Person.class).withSeed(1L).stream()
|
||||
age range : 2 .. 9919 (0 negative)
|
||||
name length range : 3 .. 10
|
||||
emails containing '@': 0 of 200
|
||||
orders per person : 2 .. 6
|
||||
sample name : EOAPEZ
|
||||
sample email : DZSPMQC
|
||||
@@ -0,0 +1,7 @@
|
||||
Instancio.create(String.class) -> 4 chars
|
||||
Instancio.ofList(Person.class).size(3) -> list of 3
|
||||
Instancio.createSet(Integer.class) -> set of 2
|
||||
Instancio.ofMap(String, Integer).size(2) -> map of 2
|
||||
Instancio.createBlank(Person.class) -> id=null name=null age=0 orders=[]
|
||||
collection size pinned to 0 via Settings -> orders=[]
|
||||
distinct names among the 3: 3
|
||||
@@ -0,0 +1,6 @@
|
||||
name = Asha Kulkarni
|
||||
email matches e-mail regex = true
|
||||
age in [18, 65] = true
|
||||
homeAddress.postalCode matches \d{6} = true
|
||||
homeAddress.country = IN
|
||||
billingAddress.country = IN // one selector, two matching fields
|
||||
@@ -0,0 +1,4 @@
|
||||
supply(name, () -> "customer-" + n) -> customer-1
|
||||
ignore(billingAddress) -> null
|
||||
ignore(age) (an int) -> 0
|
||||
withNullable(homeAddress), 200 people, seed 7 -> 40 null, 160 non-null
|
||||
@@ -0,0 +1,3 @@
|
||||
set(all(Address.class), pune) -> home=Pune, billing=Pune
|
||||
set(field(Order::status), PAID) -> statuses of 5 orders: [PAID]
|
||||
set(field(Order::total), 499.00) -> totals: [499.00]
|
||||
@@ -0,0 +1,4 @@
|
||||
subtype(payment, Card.class) -> Card
|
||||
set(payment, new Cash()) -> Cash
|
||||
card number length -> 16
|
||||
card expiry is in the future -> true
|
||||
@@ -0,0 +1,17 @@
|
||||
field(Person.class, "doesNotExist"), first 8 lines:
|
||||
org.instancio.exception.InstancioApiException:
|
||||
|
||||
Error creating an object
|
||||
-> at lab.instancio.CustomiseTest.lambda$unusedSelectorsAreAnErrorByDefault$0(CustomiseTest.java:138)
|
||||
|
||||
Reason: invalid field 'doesNotExist' for class lab.instancio.domain.Person
|
||||
set(field(Order::status), ..) on an Address graph, first 8 lines:
|
||||
org.instancio.exception.UnusedSelectorException:
|
||||
Found unused selectors referenced in the following methods:
|
||||
|
||||
-> Unused selector in: set()
|
||||
1: field(Order::status)
|
||||
at lab.instancio.CustomiseTest.lambda$unusedSelectorsAreAnErrorByDefault$1(CustomiseTest.java:139)
|
||||
|
||||
This error aims to highlight potential problems and help maintain clean test code.
|
||||
with .lenient() the same call succeeds: true
|
||||
@@ -0,0 +1,6 @@
|
||||
// 100 people, Settings: collection 1..2, string length 8..12, lower-case alphabetic, int 18..80
|
||||
orders per person : 1 .. 2
|
||||
name length : 8 .. 12
|
||||
age : 18 .. 80
|
||||
all names lower-case: true
|
||||
sample name : zopbsphrupid
|
||||
@@ -0,0 +1,7 @@
|
||||
create with seed 42, first call : LZORARZVM
|
||||
create with seed 42, second call: LZORARZVM
|
||||
a.equals(b) (whole object graph): true
|
||||
a.hashCode() == b.hashCode() : true
|
||||
create with seed 43 : UETEFLRO
|
||||
a.equals(c) : false
|
||||
seed 42 set through Keys.SEED : equals a = true
|
||||
@@ -0,0 +1,5 @@
|
||||
stream, seed 5, run 1: [QRUQXUOH, EPTMBHO, NSZCUSO, YROHHKRIGM, YXNEDMV]
|
||||
stream, seed 5, run 2: [QRUQXUOH, EPTMBHO, NSZCUSO, YROHHKRIGM, YXNEDMV]
|
||||
identical : true
|
||||
5 creates without a seed -> 5 distinct names
|
||||
seed 9 twice -> same orders list: true
|
||||
@@ -0,0 +1,2 @@
|
||||
// 300 x Instancio.of(PaymentMethod.class).withSeed(11L) (sealed: Card, BankTransfer, Cash)
|
||||
subtypes seen: {BankTransfer=90, Card=105, Cash=105}
|
||||
@@ -0,0 +1,14 @@
|
||||
Instancio.of(new TypeToken<Page<Person>>() {}).size(items, 4)
|
||||
items.size() = 4
|
||||
items.get(0) is a Person = true
|
||||
pageNumber in [1,10] = true
|
||||
Instancio.create(new TypeToken<Map<String, List<Order>>>() {})
|
||||
entries = 6, first value element is an Order = true
|
||||
Instancio.create(Page.class) (raw class, T unknown), first 8 lines of the message:
|
||||
Error creating an object
|
||||
-> at lab.instancio.GenericsAndSealedTest.rawFailureMessage(GenericsAndSealedTest.java:99)
|
||||
|
||||
Reason: incorrect type parameters specified
|
||||
|
||||
-> Class lab.instancio.domain.Page requires 1 type parameter(s): [T]
|
||||
-> The number of parameters provided was 0
|
||||
@@ -0,0 +1,5 @@
|
||||
record Percent(int value) { compact ctor rejects value < 0 or > 100 }
|
||||
Instancio.of(Percent.class).withSeed(1L), 20 instances, default ints 1..10000:
|
||||
no exception thrown; null elements: 20 of 20
|
||||
with generate(all(int.class), ints().range(0, 100)):
|
||||
null elements: 0 of 20, first values: [Percent[value=93], Percent[value=22], Percent[value=75]]
|
||||
@@ -0,0 +1,9 @@
|
||||
// instancio-junit 6.1.0 on JUnit Jupiter 6.1.3, lines collected inside the tests
|
||||
@Given field and parameter: orders 3 and 2, ages in [18, 90]: true
|
||||
@MethodSource Instancio.stream(): BWC with 3 orders
|
||||
@MethodSource Instancio.stream(): PLDXIMRQFI with 4 orders
|
||||
@MethodSource Instancio.stream(): ZQTUH with 4 orders
|
||||
@ParameterizedTest [DE] gets its own Person, age 89
|
||||
@ParameterizedTest [IN] gets its own Person, age 20
|
||||
@ParameterizedTest [US] gets its own Person, age 75
|
||||
@Seed(2026) on two different test methods + @Seed(2027) on a third: 3 Persons, 2 distinct
|
||||
@@ -0,0 +1,14 @@
|
||||
$ mvn test -Dtest=FailingSeedDemoTest -Dlab.demo=fail
|
||||
[INFO] Running lab.instancio.FailingSeedDemoTest
|
||||
SLF4J(W): No SLF4J providers were found.
|
||||
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
|
||||
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
|
||||
[ERROR] Tests run: 40, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 6.272 s <<< FAILURE! -- in lab.instancio.FailingSeedDemoTest
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[32] -- Time elapsed: 0.444 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[INFO] Results:
|
||||
[ERROR] Failures:
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] Tests run: 40, Failures: 1, Errors: 0, Skipped: 0
|
||||
lines containing '@Seed' in the whole Maven output: 0
|
||||
@@ -0,0 +1,34 @@
|
||||
$ mvn test -Pseed-log -Dtest=FailingSeedDemoTest -Dlab.demo=fail
|
||||
[INFO] Running lab.instancio.FailingSeedDemoTest
|
||||
[ERROR] Tests run: 40, Failures: 5, Errors: 0, Skipped: 0, Time elapsed: 4.204 s <<< FAILURE! -- in lab.instancio.FailingSeedDemoTest
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[4] -- Time elapsed: 0.128 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[12] -- Time elapsed: 0.030 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[24] -- Time elapsed: 0.011 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[34] -- Time elapsed: 0.008 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[ERROR] lab.instancio.FailingSeedDemoTest.everyAdultGetsADiscount(Person)[37] -- Time elapsed: 0.007 s <<< FAILURE!
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
|
||||
[main] WARN org.instancio.log.test.failure.seed - 5 tests failed. A failure can be reproduced by annotating the test method with @Seed:
|
||||
|
||||
@Seed(1592129627343010309L) FailingSeedDemoTest.everyAdultGetsADiscount repetition 4 of 40 (seed source: random seed)
|
||||
@Seed(4014505636531349958L) FailingSeedDemoTest.everyAdultGetsADiscount repetition 12 of 40 (seed source: random seed)
|
||||
@Seed(3480942169170837161L) FailingSeedDemoTest.everyAdultGetsADiscount repetition 24 of 40 (seed source: random seed)
|
||||
@Seed(2463961442792581393L) FailingSeedDemoTest.everyAdultGetsADiscount repetition 34 of 40 (seed source: random seed)
|
||||
@Seed(4455880775937018043L) FailingSeedDemoTest.everyAdultGetsADiscount repetition 37 of 40 (seed source: random seed)
|
||||
|
||||
[INFO] Results:
|
||||
[ERROR] Failures:
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] FailingSeedDemoTest.everyAdultGetsADiscount:31 age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[ERROR] Tests run: 40, Failures: 5, Errors: 0, Skipped: 0
|
||||
@@ -0,0 +1,10 @@
|
||||
$ mvn test -Pseed-log -Dtest=ReproduceFailureDemoTest -Dlab.demo=reproduce (run 1)
|
||||
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.399 s <<< FAILURE! -- in lab.instancio.ReproduceFailureDemoTest
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[main] WARN org.instancio.log.test.failure.seed - 1 test failed. A failure can be reproduced by annotating the test method with @Seed:
|
||||
@Seed(2016013118612999037L) ReproduceFailureDemoTest.everyAdultGetsADiscount (seed source: @Seed)
|
||||
$ same command again (run 2)
|
||||
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 1.159 s <<< FAILURE! -- in lab.instancio.ReproduceFailureDemoTest
|
||||
org.opentest4j.AssertionFailedError: age 18 should get a discount ==> expected: <true> but was: <false>
|
||||
[main] WARN org.instancio.log.test.failure.seed - 1 test failed. A failure can be reproduced by annotating the test method with @Seed:
|
||||
@Seed(2016013118612999037L) ReproduceFailureDemoTest.everyAdultGetsADiscount (seed source: @Seed)
|
||||
Reference in New Issue
Block a user