Assert vs Throw exception
Hi,
In BDD, When an actual results does not meet expected results, There are 2 popular ways to handles this.
1) Assert
[Given(@"the first number is (.*)")]
public void GivenTheFirstNumberIs(int p0)
{
Assert.AreEqual(p0, 0);
Living Documentation
2) Throw exception
[Given(@"the first number is (.*)")]
public void GivenTheFirstNumberIs(int p0)
{
if (p0==0)
{
throw new Exception("number can't be zero");
}
Living Documentation
which method do you favor?
0
-
Technically there is no difference.
All Assert- libraries are throwing at the end exceptions. They generate more or less readable error messages automatically.
0
Please sign in to leave a comment.
Comments
1 comment