-
-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add soft assertions for verifying unrelated subjects #1330
Comments
thanks for the feature request. I think Atrium core has everything needed for your request. but the API and some tooling (like calling the method which evaluates the expectations) is missing. one point I would like to know is how the reporting would look like. |
Oh, the reporting is a different beast. I guess we could better discuss it in a different issue. Frankly speaking, I have two cases:
|
Sorry, was writing from my mobile and did not formulate a very precise question. In the meantime I had a chance to look at the other two issues and saw the reporting example you made in the assertJ issue. That's good enough for now. I'll get back to you. In the meantime, could you please elaborate more on:
I don't get what you mean by that. How would you have expected feature to behave?
I guess that's not Atrium related but sounds like another feature request :) Would you mind to create another issue for that. Thanks |
I don't get what you mean by that. How would you have expected feature to behave? I mean that when I want to assert something, my mind flows like So I expect to write code like That works good for However, Something like the following would be way better // kotest style, however, I would prefer { ... }.asGroup {...} rather than .asClue
{ "Lazy description with $extra $comments" }.asClue {
expect(AAA).toEqual(BBB)
}
// or
expect(AAA)
.withDescription { "Lazy description with $extra $comments" }
.toEqual(BBB)
// or in AssertJ style
expect(AAA)
.describedAs { "Lazy description with $extra $comments" }
.toEqual(BBB) I believe, clarification messages are extremely important to keep test maintainable, and I am puzzled why Atrium makes it so hard to add grouping/description messages. |
For Atrium, it would be something like being able to use |
thanks for the additional example. I can see that I need to explain So whenever you think along the following lines:
then Atrium encourages you to use feature extractors instead to automatically include the identifiers of your features (in this case of properties) in reporting and, IMO equally important, to give more context by also showing the full subject (person in this example, maybe it has more properties which are also relevant to better understand why a test failed). Depending whether you want to re-state the subject-type or not you will either use (re-stating the type):
or the following (not re-stating the type, but syntax which you need to get used to)
or in case you don't care about firstName/lastName showing up in reporting even the following (easy syntax but the error report is not that good, see also: https://github.com/robstoll/atrium#feature-extractors)
And the report then looks like (for the first two alternatives)
Personally, I use grouping and description of the test-runner library for that purpose but I'll answer in more depth in the other issue you created (#1332). Following an approach how you can fulfil most of your wishes (note that @OptIn(ExperimentalWithOptions::class)
fun expectSoftly(expectations: Expect<Unit>.() -> Unit): Expect<Unit> =
expect(Unit).withOptions{
withVerb("I expected for")
withRepresentation { Text.EMPTY }
}.and(expectations)
fun <T> Expect<T>.group(groupDescription: String, assertionCreator: Expect<T>.() -> Unit) =
feature("group: $groupDescription", { this }, assertionCreator) And then you can write:
The error report then looks as follows:
Of course this can be improved with a real |
btw. Atrium has currently no extra support for ResultSet, if you created expectation functions for it, then please share them with us 😊 and in case you need help creating one then let me know |
Well, you suggest using deprecated APIs, and I'm not fond of having deprecated calls all over the place :-/ I see that I can wrap |
That is interesting question.
I tried several libraries, and got mixed results: AssertJ:
Kotest:
Now I'm evaluating Atrium |
Now that I see that there is a real use case, I am going to remove the deprecation with the next release. shouldn't be a blocker. in file A:
in test:
I guess this way your expect will have precedence over the deprecated version. make sure you import it without star. |
I can actually think of situations where I did not use Atrium and soft assertions had to be added in a
|
btw. did you see https://github.com/robstoll/atrium#data-driven-testing -- it's not like Atrium does not support soft assertions already 🙂 -- but I see that we can improve here further |
This sounds good to me.
Not really. That is why I want to run the procedure in the DB once, and then assert multiple things: the expected small changes for the given test, the overall system health, logs, and metrics. The tests run with TestNG, and the current assertions are like "build a big string with all the assertion material, and then assert with |
I've prepared some wrappers to reduce verbosity, and I migrated the above Well, I have two issues:
I'm going to try a compiler plugin so expect(rs.getString("name")) would yield report like "I expect rs.getString("name"): actual value..." |
@vlsi as mentioned by you in #1332 (comment)
I intend to add this entry-point to atrium as well. Currently I was considering one of the following:
I kind of like the idea that a user of Atrium always has to write I am currently in favour of |
I agree it is nice to type expect, and then decide how to proceed. |
un-deprecate nested `expect`s in preparation of #1330
I will move expectCollector to a separate issue because the main topic of this issue, make it simpler to create expectations for unrelated subjects is solved now with |
@vlsi I forgot to create the issue for expectCollector back in October 🙈 Now that I think about it again I am not yet fully convinced we really need it. So I wonder, do you still have a use case for it where you actually want to collect failures in the test and add further test failures caused by an afterTest (or similar) callback, now that Atrium provides I first figured expectCollector could be helpful if you want to pass
The only missing piece here is extractSubject and I remember from the discussion about ResultSet, that we decided to introduce something like it (#1344 (reply in thread)) Of course, this would not help if someone really want to state expectations in an @Before/AfterTest or the like. But maybe we can neglect this and ask users which really need this to create a CollectingExpect manually? Did you have such a use case lately? |
Creating
|
Platform (all, jvm, js): all
I would like to have multiple soft assertions for unrelated subjects.
For instance, here's something I have in mind.
Note the following:
group
for creating a group for output purposes. In other words, it should be included in the failure messages, however, it does not correspond to a subjectexpect(..)
. For instance, I would like to have some of the verifications in@AfterEach
, and some of the verifications inside the test method itself.Frankly speaking, I do not see the way to add "groups" for description purposes.
At the same time,
feature
API is unexpected, and it deviates fromexpect(...)
.In other words, a top-level
expect
isexpect(subject).toEqual(target)
, whilenested
feature
isfeature("description") { subject }.toEqual(target)
.Here's the similar requests for other assertion libraries:
Edit by @robstoll
To sum up, I plan in 1.0.0
expect
within an expectation groupin 1.1.0
fun expectGrouped(description: String = null)
as entry point (including an optional group description)group
=> both group and expectGroup will have#
as bullet point.I plan in 1.2.0 (or 1.3.0):
to add(see Add soft assertions for verifying unrelated subjects #1330 (comment)) => addition is considered to be too risky for wrong usage, won't be added for nowexpectCollector()
The text was updated successfully, but these errors were encountered: