Can I configure NUnit so that Debug.Fail doesn't show a message box when I run my tests?

Posted by panamack on Stack Overflow See other posts from Stack Overflow or by panamack
Published on 2010-04-18T11:20:47Z Indexed on 2010/04/18 11:23 UTC
Read the original article Hit count: 273

Filed under:
|
|

I have this property:

    public SubjectStatus Status
    {
        get { return status; }
        set
        {
            if (Enum.IsDefined(typeof(SubjectStatus), value))
            {
                status = value;
            }
            else
            {
                Debug.Fail("Error setting Subject.Status", "There is no SubjectStatus enum constant defined for that value.");
                return;
            }
        }
    }

and this unit test

    [Test]
    public void StatusProperty_StatusChangedToValueWithoutEnumDefinition_StatusUnchanged()
    {
        Subject subject = new TestSubjectImp("1");

        //  assigned by casting from an int to a defined value
        subject.Status = (SubjectStatus)2;
        Assert.AreEqual(SubjectStatus.Completed, subject.Status);            

        //  assigned by casting from an int to an undefined value
        subject.Status = (SubjectStatus)100;
        //  no change to previous value
        Assert.AreEqual(SubjectStatus.Completed, subject.Status);            
    }

Is there a way I can prevent Debug.Fail displaying a message box when I run my tests, but allow it to show me one when I debug my application?

© Stack Overflow or respective owner

Related posts about c#

Related posts about debugging