Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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