Skip to content

Instantly share code, notes, and snippets.

@carbonrobot
Created February 11, 2015 20:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carbonrobot/fd5780bbf0f1c01e6256 to your computer and use it in GitHub Desktop.
Save carbonrobot/fd5780bbf0f1c01e6256 to your computer and use it in GitHub Desktop.
Unit testing in Linqpad
public interface IRunner { void Execute(); }
// Add any unit tests by implementing IRunner and Linqpad will run it
public class UserTest_1 : IRunner
{
public void Execute()
{
Debug.WriteLine("Beginning test");
var x = 4 + 5;
Debug.Assert(x == 9, "Test failed!");
}
}
// Linqpad main method
void Main()
{
var tests = typeof(UserQuery)
.GetNestedTypes()
.Where(type => typeof(IRunner)
.IsAssignableFrom(type) && !type.IsInterface);
foreach(var t in tests){
(Activator.CreateInstance(t) as IRunner).Execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment