Make Finance provider's UnionPay test more readable, especially on failure#1643
Make Finance provider's UnionPay test more readable, especially on failure#1643kingthorin merged 2 commits intodatafaker-net:mainfrom
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1643 +/- ##
============================================
+ Coverage 92.38% 92.42% +0.04%
- Complexity 3382 3383 +1
============================================
Files 333 333
Lines 6681 6681
Branches 664 664
============================================
+ Hits 6172 6175 +3
+ Misses 349 347 -2
+ Partials 160 159 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| assertThat(creditCard).hasSize(16); | ||
| assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81")).isTrue(); | ||
| assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81")) | ||
| .as("UnionPay credit card number begins with the correct digits") |
There was a problem hiding this comment.
Could you concatenation credit card here so the actual generated value is visible?
There was a problem hiding this comment.
@Fishbowler Something like this:
assertThat(creditCard.startsWith("62") || creditCard.startsWith("64") || creditCard.startsWith("65") || creditCard.startsWith("81"))
.as(() -> "UnionPay credit card number begins with the correct digits, but received: " + creditCard)
.isTrue();There was a problem hiding this comment.
Oooh, that's even better! ❤️
There was a problem hiding this comment.
Fixed
org.opentest4j.AssertionFailedError: [Expected UnionPay credit card number to begin with the correct digits (62, 64, 65, 81), but received: 1221262098276253]
Expecting value to be true but was false
Expected :true
Actual :false
There was a problem hiding this comment.
I'd like to propose:
@RepeatedTest(100)
void unionpayCard() {
List<String> startingDigits = List.of("62", "64", "65", "81");
String creditCard = finance.creditCard(CreditCardType.UNIONPAY).replace("-", "");
assertThat(creditCard).hasSize(16);
assertThat(startingDigits.contains(creditCard.subString(0,2))
.as(() -> "Expected UnionPay credit card number to begin with the correct digits " + startingDigits + ", but received: " + creditCard)
.isTrue();
}af1a64b to
1ed4f00
Compare
1ed4f00 to
c00fa22
Compare
9c55e85 to
145ef25
Compare
Makes a test in the Finance provider easier to read, and gives actionable feedback to the developer when it fails.
Addresses the comment left on the previous PR.