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
Assert check not consistent #1773
Comments
Are you using the |
@LeonteDenismsgDev about your example - you can add an additional assert that result is not empty. |
The following is our general policy on questions of this sort: Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. We prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug. Having said that, and since you're "just a junior", let me say the following. JUnit does not perform static analysis of your compiled code and therefore has no way to know if your code performs an assertion. The best you can do is to ensure that you perform the necessary assertions in your tests. For the example you gave, you could assert the size of the Alternatively, I believe there are some IDEs and plugins for IDEs that check whether your tests perform actual assertions. In light of the above, I am closing this issue. |
@LeonteDenismsgDev Instead of using Java's import static org.junit.Assert.assertTrue;
@Test
public void test1(){
result = method();
helper(result);
}
public void helper(List<Object> result){
for(int i = 0; i < result.size(); i++){
assertTrue(condition);
}
} |
If I understood @LeonteDenismsgDev correctly, the reason that |
In that case, I'd suggest adding another assertion that checks the list is not empty: |
Yep, that's what I meant when I suggested this:
Though, admittedly I should have explicitly stated that one should assert the size is not 0 (that the list is not empty). 😉 |
yeah thats about it,. Sorry for the absence, being the weekend and stuff. @sbrannen thanks for the explanation in the closing comment, now I understand why its not supposed to warn me. Just a clarification: I did say assert but in the code I used AsserEquals (at that time not knowing you can assertEquals arrays) and now I got rid of that loop so the problem is not there anymore. Welp thank you all |
@LeonteDenismsgDev, you're welcome. And we're glad we were able to help you sort it out. |
So I was writing some tests for some lists and I noticed that if an assert is inside a loop but the loop by some erroneous behavior wont start I noticed that the test passes and the runner gives no warning whatsoever that the test doesnt actually run any assert at all. Maybe this is just me being stupid but I think it could be helpful to at least get warned whenever a test doesnt run any assert.
For example:
Please pay no mind to my example, its just a proof of concept and it doesnt actually reflect my exact situation but the problem is that.
Please be respectful for my naivety, im just a junior =))
The text was updated successfully, but these errors were encountered: