by Patrik Hägne via Legend and truth on 5/21/2009 10:41:00 PM
There are quite a few nice features in the new 2.5 release of NUnit so if you’ve not yet checked it out please do so. I’ve migrated to it in all our solutions at work and we’ve had no problems, we did have to upgrade to the latest versions for TestDriven.Net and TeamCity, but hey, upgrading is a good thing.
One thing I really like is the ValuesAttribute, if you’ve done parameterized tests (that were previously available in the NUnit.Framework.Extensions library) this is something similar. Just tag your test as a normal Test-method but add a parameter and tag that parameter with the ValuesAttribute like this:
[TestFixture] public class ValidatorTests { [Test] public void IsInRange_returns_true_for_values_that_are_in_range([Values(1,2,3)] int value) { var validator = new Validator(); validator.IsInRange(value, 1, 3); } } public class Validator { public bool IsInRange(int value, int lowerBound, int upperBound) { return value >= lowerBound && value <= upperBound; } }
This will result in three tests being run, one for each value, quite nice.
The really cool thing is that you can add more than one parameter each tagged with this attribute and the number of tests will be the cross-product of the values.
Original Post: NUnit ValuesAttribute is tasty delicious!
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.