Yoda
Yoda

Reputation: 18068

Define how many asserts are expected when using Microsoft.VisualStudio.TestTools.UnitTesting or NUnit

I write a test where I expect exactly one assertion to be performed. When I was writing tests in qUnit I was able to state assert.Expect(1) what means that if there will be 0 or more than 1 assertion the test will fail.

Is it possible in the Microsoft.VisualStudio.TestTools.UnitTesting maybe with some annotations?

Upvotes: 0

Views: 50

Answers (1)

eocron
eocron

Reputation: 7546

There is no implementation. At least I looked into decompiled source and don't see any state changing inside Assert operation, just simple return on success.

I consider you to wrap all asserts with your own and count calls yourself, then just write some Assert.Expect() in the end and upon it check how much calls were made from previous state.

Though this method will fail if you run tests asynchronously and you will need to inspect stack trace for each call and count it from stack trace of MyAssert.Expect(666) call.

Upvotes: 2

Related Questions