开发者

Does it make sense to test assertArrayHasKey and later test value using assertEquals?

开发者 https://www.devze.com 2023-03-18 14:58 出处:网络
Does it make sense to test assertArrayHasKey and later test it\'s value using assertEquals, or when I\'m expecting specific value, I should 开发者_如何学运维ommit testing testArrayHasKey - I will get

Does it make sense to test assertArrayHasKey and later test it's value using assertEquals, or when I'm expecting specific value, I should 开发者_如何学运维ommit testing testArrayHasKey - I will get "Undefined index: id" in the next assertion anyway.

I'm aware that difference is in feedback (F vs. E) but does it make any difference in real life?


An error will show you that something in your test didn't met your expectations, you as the person writing the test.

For the expectation of the test, it will fail in case of error as well. So you will get a "fail" in both ways.

So it depends what you expect. If in normal operation the array will have the key and you're interested in testing for a specific value, assert the value and you're done. Keep tests simple.

If it's more common that you get an error in there then, your test might not be actually fitting your needs so getting an error will then signal you that you might want to refactor your test(s).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号