Last active
January 1, 2016 21:07
-
-
Save amirrajan/7ee4777788e6a5d76fee to your computer and use it in GitHub Desktop.
NSpec Program.cs
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 NSpec; | |
using NSpec.Domain; | |
using NSpec.Domain.Formatters; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using System.Text; | |
using System.Threading.Tasks; | |
using FluentAssertions; | |
namespace HelloTests | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//types that should be considered for testing | |
var types = Assembly.GetExecutingAssembly().GetTypes(); | |
//now that we have our types, set up a finder so that NSpec | |
//can determine the inheritance hierarchy | |
var finder = new SpecFinder(types); | |
//we've got our inheritance hierarchy, | |
//now we can build our test tree using default conventions | |
var builder = new ContextBuilder(finder, new DefaultConventions()); | |
//create the nspec runner with a | |
//live formatter so we get console output | |
var runner = new ContextRunner( | |
builder, | |
new ConsoleFormatter(), | |
false); | |
//create our final collection of concrete tests | |
var testCollection = builder.Contexts().Build(); | |
//run the tests and get results (to do whatever you want with) | |
var results = runner.Run(testCollection); | |
//console write line to pause the exe | |
System.Console.ReadLine(); | |
} | |
} | |
class describe_world : nspec | |
{ | |
void it_exists() | |
{ | |
true.Should().BeTrue(); | |
} | |
void it_doesnt_exist() | |
{ | |
false.Should().BeTrue(); | |
} | |
void nested_test() | |
{ | |
it["exists"] = () => true.Should().BeTrue(); | |
it["doesn't exist"] = () => false.Should().BeTrue(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment