Created
January 13, 2015 09:11
-
-
Save raybooysen/5cf4c9b74a7d35d9ba0b to your computer and use it in GitHub Desktop.
Shouldy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using NUnit.Framework; | |
using Shouldly; | |
namespace ClassLibrary1 | |
{ | |
[TestFixture] | |
public class Fixture | |
{ | |
private IEnumerable<Foo> AllTypes | |
{ | |
get | |
{ | |
yield return new Foo(true); | |
yield return new Foo(false); | |
} | |
} | |
[TestCaseSource("AllTypes")] | |
public void AllValuesShouldBeBar(Foo foo) | |
{ | |
foo.IsBar.ShouldBe(false); | |
} | |
} | |
public class Foo | |
{ | |
public Foo(bool isBar) | |
{ | |
IsBar = isBar; | |
} | |
public bool IsBar { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this example, which is very common, we might have a test case source of some type that we test many values. Because we can't append any message to the ShouldBe() call, we can't provide any information to the test runner why this failed for a specific instance.
Common scenarios that exist are convention based tests like "All files suffixed with ViewModel should implement INotifyPropertyChanged." In this example, in a big project, I'd like to be able to output the type that was being tested, so when we fail 5 out of 500 VMs, it's obvious which type has failed.
These are just two examples, but more exist, there are cases where, while the output from Shouldly is good, we want to give the user more context.