This question has been asked in various forms in a number of different forums, but, IMHO, I haven\'t been able to find a place where it\'s really answered clearly, so I\'m g
Please read ExpectedExceptionAttribute documentation carefully, it is nowhere stated that tests the exception message so it's not a bug that is not asserted.
The second parameter is the assert message what is displayed when expected exception type is not thrown, not the expected exception message. I.e. like the second parameter in Assert.IsTrue(condition, message).
You can change the code in NUnit because it is open source. You can't do that with MSTest.
Roy, Bunch of your information is out of date especially as it relates to 2010;
Nunit contains a [TestCase] attribute that allows implementing parametrized tests. this does not exist in MSTest
This can be implemented using unit test extensibility in 2010.
MSTest's ExpectedException attribute has a bug where the expected message is never really asserted even if it's wrong - the test will pass.
Correct thats still there
NUnit has an Assert.Throws API to allow testing an exception on a specific line of code instead of the whole method (you can easily implement this one yourself though)
Jim implented a version of Assert.Throws for MSTest at the same time as he did the original implementation for NUnit, NUnit has included in subsequent releases, MSTest has not, its still possible to use though.
NUnit contains a fluent version of Assert API (as already mentioned - Assert.That..)
There are several of these implemented by 3rd parties for MSTest
NUnit is much faster
See Jamie's comment he has managed to get MSTest running faster :-)
NUnit can run tests in 32 and 64 bit (MSTest only runs them in 32 bit IIRC)
Not in 2010, 64 bit support is built in.
NUnit allows abstract classes to be test fixtures (so you can inherit test fixtures). MsTest does not.
This works but not across assemblies which does limit its usefulness.
NUnit allows non public classes to be test fixtures (as of the latest version)
Still there
NUnit was created SOLELY for the idea of unit testing. MSTest was created for Testing - and also a bit of unit testing.
Correct, there is a lot of misconception that MSTest is the same as Nunit but MSTest is a generalized framework.
NUnit contains PNunit (running parallel tests with NUnit). MSTest only adds this ability in vs 2010
Correct there is an XML config setting that allows control of degree of parallelism.
I have a nice way in between MsTest and NUnit. You can use the MSTest framework to run your test (TestClass attribute and TestMethod attribute for each test) but use the NUnit Assert API.
just do this :
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Assert = NUnit.Framework.Assert;
now you can use Assert.That(..) and still have TFS automated build and test report. your test can be run in VS, TestDriven.net or Resharper, it doesnt matter, the test will fail or pass correctly, and the fail output will be according to NUnit framework.
see here : http://alsagile.com/archive/2010/03/09/stop-the-war-between-nunit-and-mstest-make-them.aspx
You can very easily run NUnit tests on Linux with Mono and I don't think you can do that with tests for MSTest.
See http://fluentassertions.codeplex.com. You can do stuff like
"ABCDEFGHI".Should().StartWith("AB").And.EndWith("HI").And.Contain("EF").And.HaveLength(9);
new[] { 1, 2, 3 }.Should().HaveCount(4, "because we thought we put three items in the
collection"))
dtoCollection.Should().Contain(dto => dto.Id != null);
collection.Should().HaveCount(c => c >= 3);
dto.ShouldHave().AllPropertiesBut(d => d.Id).EqualTo(customer);
dt1.Should().BeWithin(TimeSpan.FromHours(50)).Before(dt2);
Action action = () => recipe.AddIngredient("Milk", 100, Unit.Spoon);
action
.ShouldThrow<RuleViolationException>()
.WithMessage("Cannot change the unit of an existing ingredient")
.And.Violations.Should().Contain(BusinessRule.CannotChangeIngredientQuanity