Skip to content

7. Exception handel

Kamruzzaman edited this page Nov 13, 2019 · 1 revision

Example 1 / Example 2

   //Example 1:-
    [ExpectedException(typeof(ArgumentException))] //<---
    public void NumberOfFruits_NegativeValue_Exception(int person, int expected)
    {
        //Act
        var original = manual.NumberOfFruits(person);

        //Assert
        Assert.AreEqual(original, expected);
    }

    //Example 2:-
    //Act
    try
    {
        var original = manual.NumberOfFruits(person);
    }
    catch (ArgumentException)
    {
        // The test succeeded
    }
Clone this wiki locally