Support writing unit tests
Allow us to create unit tests using NUnit or similar (either needs a new option in the Language dropdown or a one-liner you could put in your Main function to kick off a test runner). Running it would run all the Unit Test methods it finds. Taking this one step further, you could even support an auto-test mode, where every time you saved, if it compiles it runs all the unit tests it finds, making it the ideal for doing code katas in
LINQPad now has special xunit support as of 6.9.12, via new options on the Query menu. ‘Add XUnit Test Support’ adds the necessary dependencies + creates a customizable xunit runner. “Run Tests” (shortcut Alt+Shift+R) invokes the RunTests() method.
-
Murray Gregory commented
Here is a code snippet for typing "nunit" and have it give a template using NUnitLite:
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>nunit</Title>
<Description>nunit - assemblies and namespaces</Description>
<Shortcut>nunit</Shortcut>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>nuget:NUnitLite</Assembly>
</Reference>
</References>
<Imports>
<Import>
<Namespace>NUnit.Framework</Namespace>
<Namespace>NUnit.Options</Namespace>
<Namespace>NUnitLite</Namespace>
</Import>
</Imports>
<Declarations>
<Literal>
<ID>TestName</ID>
<Default>WhenXShould</Default>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[void Main()
{
new AutoRun().Execute(new[]{"--noheader","--noresult"});
}[TestFixture]
public class TestHarness
{
// Write your tests here
[TestCase("scenario", 0)]
public void $TestName$(string scenario, int expectedValue)
{
// setup// execute
var actual = 0;// verify
Assert.That(actual, Is.EqualTo(expectedValue), scenario);
}}]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets> -
Murray Gregory commented
If you use NUnitLite 3.0, you'll need to call it this way:
NUnitLite in 3.0 uses the following format,
public static void Main(string[] args)
{
new AutoRun().Execute(args);
}See
https://groups.google.com/forum/#!topic/nunit-discuss/AU7ZX0v8ToQ
-
Murray Gregory commented
I use NUnit Lite to write and execute tests in LINQPad.
http://scriptbucket.wordpress.com/2014/03/16/how-to-unit-test-a-linqpad-code-snippet/
-
Haynesy commented
Damn you read my mind, with the exception of having growl notifications so as to not wait for test completion.
-
Maslow commented
or perhaps MSTest =)