Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
645 views
in Technique[技术] by (71.8m points)

.net - How to prevent expected exceptions from breaking the debug test run?

When running MSTEST unit tests in debug mode, the execution stops in every expected exception that is thrown. My test looks like this

[TestMethod()]
[ExpectedException(typeof(ArgumentNullException))]
public void ShouldThrowExceptionWhenPassingNull()
{
    object data = null;
    target.CheckNull(data);
}

the target method looks like this:

public void CheckNull(object data)
{
    if (ReferenceEquals(null, data))
    {
        throw new ArgumentNullException("data");
    }
} // test run breaks here: ArgumentNullException was unhandled by user code
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you try running the tests using ctrl-R ctrl-T instead of ctrl-R T?

EDIT If it's not a keyboard shortcut issue, then check out this link. You could try the following as noted there:

  1. Disable "break on user unhandled exceptions" for the exception types you you are encountering here (via Debug -> Exceptions)
  2. Disable "break on user unhandled exceptions" for all exceptions (via Debug -> Exceptions)
  3. Disable "Just My Code"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...