Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent of assert.warning in mstest?

Tags:

is there a MsTest Equivalent of Assert.Warning in MbUnit ?

like image 460
Hannoun Yassir Avatar asked Sep 02 '09 19:09

Hannoun Yassir


People also ask

How do I assert exceptions in MSTest?

There are some complexities to this which will come in another blog post, but the result is we can now use the following syntax to assert an exception in MSTest: Assert. Throws(() => sc. Add("-1"));

Can we use try catch in unit test C#?

In your unit test case, you can use a try-catch block. Let me show you what I mean. You use the try block to execute the code under test. If the method throws an exception, that will be covered by the catch block.

What are asserts unit test?

The assert section ensures that the code behaves as expected. Assertions replace us humans in checking that the software does what it should. They express requirements that the unit under test is expected to meet. Now, often one can write slightly different assertions to capture a given requirement.


2 Answers

The closest match is Assert.Inconclusive() - it doesn't make the test fail as such, but it doesn't succeed either. It fall into a third stage called Inconclusive.

A single Inconclusive test will cause an entire test suite to be Inconclusive.

There are overloads that supports custom messages as well:

Assert.Inconclusive("Ploeh");
like image 168
Mark Seemann Avatar answered Sep 30 '22 19:09

Mark Seemann


I have a similar issue as I use NUnit for some projects. Try using

Console.Write("Some Warning");
like image 40
MattyC Avatar answered Sep 30 '22 19:09

MattyC