-
Notifications
You must be signed in to change notification settings - Fork 884
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
[sinttest] Add AbstractSmackIntTest.assertResult() #583
[sinttest] Add AbstractSmackIntTest.assertResult() #583
Conversation
When an assertion fails, it should throw an Returning a value in an assertion is an anti-pattern. An assertion should only do that: assert something - not also produce a value that is expected to be used in follow-up code (arguably, asserting something is the last thing in a test anyway, as they should be concise). |
0adb133
to
1584d3d
Compare
Right, I noticed that sitting on the couch too. See updated revision.
What would be the argument for such an artificial limitation? Seems pointless to declare it an anti-pattern when it is clearly useful. It is also established practice, see, for example, That said, you are free to simply ignore anything that the function returns. |
Note that a 'timeout' also is an assertion failure - it might even be be the primary assertion done when this class is used, as validation of the returned value often is not done at all. |
1584d3d
to
dc96484
Compare
I've refactored #582 to include the changes proposed by you here, adjusted for my feedback. |
I could get maybe convinced to change the result type from SimpleResultSyncPoint to void. But, as we both discovered, this can be sorted out later. On the other hand, I am sorry but I am confident that wrapping the |
I guess we just don't agree on the For posterity, as the following was exchanged in a chat that even I can't find anymore: The test execution frameworks can/will report differently on a test execution problem, depending on the exception that's being thrown is or isn't an For my purpose, it's important to flag as accurately as possible if a test execution is failing because the system under test is misbehaving, or because the test implementation has a bug - especially so since in our context, people that execute the tests are different people than Smack/SINT developers. That makes it more important to accurately identify the source of the test execution problem: in case of an assertion failure, the person executing the test should start to investigate their own system under test. In case of a test bug, they should file a report with our project. When public class TempTest
{
@org.junit.jupiter.api.Test
public void testFail() throws Exception {
// Result displayed as an 'cross' icon, alt-text "Assertion failure"
org.junit.jupiter.api.Assertions.fail();
}
@org.junit.jupiter.api.Test
public void testEquals() throws Exception {
// Result displayed as an 'cross' icon, alt-text "Assertion failure"
org.junit.jupiter.api.Assertions.assertEquals("foo", "bar");
}
@org.junit.jupiter.api.Test
public void testThrowAssertionError() throws Exception {
// Result displayed as an 'cross' icon, alt-text "Assertion failure"
throw new AssertionError();
}
@org.junit.jupiter.api.Test
public void testThrowOpenTest4jAssertionFailedError() throws Exception {
// Result displayed as an 'cross' icon, alt-text "Assertion failure"
throw new org.opentest4j.AssertionFailedError();
}
@org.junit.jupiter.api.Test
public void testThrowTimeoutException() throws Exception {
// Result displayed as an 'exclamation mark' icon, alt-text "Unexpected exception"
throw new java.util.concurrent.TimeoutException();
}
@org.junit.jupiter.api.Test
public void testThrowIllegalArgumentException() throws Exception {
// Result displayed as an 'exclamation mark' icon, alt-text "Unexpected exception"
throw new IllegalArgumentException();
}
@org.junit.jupiter.api.Test
public void testThrowNullPointerExceptionException() throws Exception {
// Result displayed as an 'exclamation mark' icon, alt-text "Unexpected exception"
throw new NullPointerException();
}
@org.junit.jupiter.api.Test
public void testDivisionByZero() {
// Result displayed as an 'exclamation mark' icon, alt-text "Unexpected exception"
org.junit.jupiter.api.Assertions.assertEquals(999, 2/0);
}
} |
I totally agree. Where we seem to disagree is where the boundary between "test failed due to the system under test failed" and "test failed for other reasons, like out of memory" is drawn. You seem to argue that it is AssertionError exception vs (all?) other exceptions. However, I believe it is exceptions subclassing You also do not seem to be fully convinced of your argumentation, because when I asked you if But then, you end up with code wrapping exceptions, That is one of the main reasons I dislike the idea to wrap things in |
Counter proposal to #582