question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assert true/false with multiple conditions

See original GitHub issue

Say 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:closed
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
alb-i986commented, May 28, 2015

Uhm… I don’t think so.

My client code is this at the moment:

assertTrue("", a.xxx() && b.yyy() && c.zzz())
0reactions
kcooneycommented, May 28, 2015

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found