开发者

Guidelines for using Assert versus Verify

开发者 https://www.devze.com 2023-01-01 01:41 出处:网络
I\'m new to unit testing, and I\'m learning how to use NUnit and Moq. NUnit provides Assert syntax for testing conditions in my unit tests, while Moq provides some Verify functions. To some extent the

I'm new to unit testing, and I'm learning how to use NUnit and Moq. NUnit provides Assert syntax for testing conditions in my unit tests, while Moq provides some Verify functions. To some extent these seem to provide the same functionality.

How do I know when it's more appropriate to use Assert or Verify?

Maybe Assert is better f开发者_StackOverflow社区or confirming state, and Verify is better for confirming behavior (Classical versus Mockist)?


Your assumption about Assert to confirm State and Verify to confirm behavior is correct.

You Assert a result, or a value

You Verify that a method has been called with appropriate parameters.


From selenium point of view, Assert is a validation that if is not meet, it stops the test there and reports as fail. Instead, verify is a validation that if not meet, then continues with the test and it reports the test as failed at the end of the execution.

So, if the validations are dependent, I recommend to use assert. if validations are not dependent, then use verify.

Reference: https://www.softwaretestingmaterial.com/difference-between-assert-and-verify/

0

精彩评论

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