After the very good feed back of the previous post, the new look of NUnitEx is:
Bollean Constraints:
actual.Should().Be.True();
actual.Should().Be.False();
Object Constraints:
actual.Should().Be.Equal(something);
actual.Should().Be.Null();
actual.Should().Be.SameInstanceAs(something);
actual.Should().Be.InstanceOf<SomeClass>();
actual.Should().Be.OfType<SomeClass>();
actual.Should().Be.AssignableFrom<SomeClass>();
actual.Should().Be.AssignableTo<SomeClass>();
actual.Should().Be.BinarySerializable();
actual.Should().Be.XmlSerializable();
Each constraint allow negation as : actual.Should().Not.Be.Equal(something);
Struct/Struct? Constraints
actual.Should().Be.LessThan(maxvalue);
actual.Should().Be.GreaterThan(minvalue);
actual.Should().Be.LessThanOrEqual(maxvalue);
actual.Should().Be.GreaterThanOrEqual(minvalue);
actual.Should().Be.Equal(actual);
Each constraint allow negation as : actual.Should().Not.Be.Equal(minvalue);
String Constraints
actual.Should().Be.Equal("a");
actual.Should().Be.Empty();
actual.Should().Be.Null();
actual.Should().Contain("some");
actual.Should().StartWith("some");
actual.Should().EndWith("ing");
actual.Should().Match("ome[tT]h");
Each constraint allow negation as : actual.Should().Not.Be.Equal("a string");
Enumerable Constraints
actual.Should().Have.SameSequenceAs(new[] { 1, 2, 3 });
actual.Should().Be.Null();
actual.Should().Be.Empty();
actual.Should().Be.SameInstanceAs(expected);
actual.Should().Contain(expected);
actual.Should().Have.SameValuesAs(new[] { 3, 2, 1 });
actual.Should().Have.UniqueValues();
actual.Should().Be.SubsetOf(new[] { 1, 2, 3, 4 });
actual.Should().Be.Ordered();
Each constraint allow negation as : actual.Should().Not.Have.SameSequenceAs(new[] { 3, 1 });
What next
Allow concatenation:
actual.Should().Not.Be.Null()
.And.Contain(expected)
.And.Have.UniqueValues();
Perhaps some new custom assertions for IEnumerable<T>.
Some constraints for Action as, for example:
new Action(() => new Something(null)).Should().Throw<ArgumentNullException>()
.Where.Message.Should().StartsWith("The parameter");
At last I’m studying the possibility to have the same API for others Unit-Test frameworks as xUnit, MbUnit and so on.
Remember that your feedback is very important.
I don't like the name actual. I feel result is more compelling and tells me more about what we are testing
ReplyDeleteBut I kind of like this approach.
Well... in the post "actual" is only to be short and it represent the variable you are testing.
ReplyDeleteFor example:
string somethig;
......
somethig.Should().StartsWith("Benn");
I know that, but for newbies to testing, actual doesnt mean anyting. But everyone can relate to testing a result.
ReplyDeleteBut this is beside this good blog.
You do a fantastic job.
Benny
I like every one but this:
ReplyDeleteactual.Should().Be.Equal(something);
Can't it be EqualTo?
string somethig;
ReplyDelete......
somethig.Should().Be.Null();
It does not have sense... because if "something" is null it will throw an exception :). Am I wrong?
@Diego
ReplyDeleteYes, you are. ;)
Cool!. I'm not really used to Extension Methods yet...
ReplyDeleteI've never tried it, but somewhere must be a simple test that proves it works.
Thanks Tano.
Do you mean something like this ?
ReplyDeletehttp://code.google.com/p/nunitex/source/browse/trunk/NUnitEx/NUnitEx.Tests/StringConstraintsFixture.cs
100% code (well... today is 99%)