Assert true/false with multiple conditions
See original GitHub issueSay that you need to make an assertion over multiple boolean conditions, and you want them all to be true (or false).
Currently:
assertTrue(message1, condition1);
assertTrue(message2, condition2);
...
assertTrue(msg_n, cond_n);
But I want the test not to fail at the first unmet condition:
Def: assertTrue(boolean... conditions);
Usage: assertTrue(condition1, condition2, ..., cond_n);
But I would like to specify a message for each condition, in order to have a meaningful error message, in case of failure. So maybe:
Def: assertTrue(SelfDescribingBoolean... conditions);
Usage: assertTrue(bool(msg1, cond1), bool(msg2, cond2)...);
where bool
is a factory method for building SelfDescribingBoolean
?
I know of hamcrest’s composite matcher allOf
but it doesn’t help when you want to run many matchers against many subjects (one-to-one), does it?
An alternative could probably be overloading assertThat so that it can support multiple subjects?
Thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
How to assert once with multiple conditions? - python
In this case the function is extremely simple, the tests have no real value, as they just do the same and assert that...
Read more >Multiple JUNIT Asserts Can Combine Into One Single ... - DZone
Problem 1 can achieve by combining multiple conditions by using && operator but the issue is to difficult know which one is failed....
Read more >Python Assert Statements - codingem.com
The assert statement checks if a condition evaluates True. ... Where the two parameters are: condition: the condition against which you test your...
Read more >Is it OK to have multiple asserts in a single unit test?
My solution is to use one assert but with several values: String actual = "val1="+val1+"\nval2="+val2; assertEquals( "val1=5\n" + "val2=hello" , actual );.
Read more >ASSERT statement - IBM
The ASSERT statement asserts whether a condition is true or false, compares two values and determines if they are equal, or asserts whether...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Uhm… I don’t think so.
My client code is this at the moment:
We tend to avoid APIs that require method chaining (other than builders).
It is extremely challenging to write an expressive, extensible and easy to use assertion API, and what makes a good assertion API is a matter of taste. If that kind of API is something you like, I suggest an assertion framework like Truth, Fest or Hamcrest.