Created
February 11, 2015 20:03
-
-
Save carbonrobot/fd5780bbf0f1c01e6256 to your computer and use it in GitHub Desktop.
Unit testing in Linqpad
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
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