Coder Social home page Coder Social logo

scriptcs-nunit's Introduction

ScriptCs.NUnit

Script pack for running nunit tests from scriptcs

Installation

From the folder where you are writing a script, run:

scriptcs -install scriptcs.nunit

This will install ScriptCs.NUnit and the necessary dependencies.

Usage

You can now write and run NUnit unit tests in your scriptcs CSX file.

Tests for CSX

[TestFixture]
public class Tests
{
  [Test]
	public void ScriptcsShouldBeAwesome()
	{
		var scriptcsIsAwesome = true;
		Assert.IsTrue(scriptcsIsAwesome);
	}
 }

var nunit = Require<NUnitRunner>();
nunit.RunAllUnitTests(); 

This will simply run all the unit tests in the given script context. It will also find tests referenced by #load. This way you can test your CSX code, with CSX unit tests.

Tests from external file

You can also reference an external assembly containing NUnit tests and run these.

For example, consider a MyTests.dll which contains some unit tests in the UnitTests class. You can copy that DLL to the bin folder and do the following (passing in the Assembly instance):

#r "MyUnitTests.dll"

var nunit = Require<NUnitRunner>();
nunit.RunAllUnitTests(typeof(MyUnitTests.UnitTests).Assembly); 

Writing tests for code from external DLL

Using the same technique, you can import an external DLL, and write unit tests for that DLL in CSX. For example, consider a hypothetical MyAssembly.dll with a MyClass class. You can do the following:

#r "MyAssembly.dll"
using MyAssembly;

[TestFixture]
public class Tests
{
  [Test]
	public void MyClassShouldNotBeNull()
	{
		var myClass = new MyClass();
		Assert.NotNull(myClass);
	}
 }

var nunit = Require<NUnitRunner>();
nunit.RunAllUnitTests(); 

Other considerations

The RunAllUnitTests() method actually returns an instance of NUnit.Core.TestResult which contains all info about the tests run - such as assert count, individual failures/successes, execution time and many more details regarding each test. With this, you can programmatically discover the status, and - for example - program automated tasks to depend on unit tests.

Important! This script pack only works in debug mode. It means, you have to execute your CSX like this:

scriptcs start.csx -debug

Script pack also exposes an overload:

TestResult RunAllUnitTests(Action<string> callback, Assembly testAssembly = null)

where you can redirect the test output from Console (default behavior) to anywhere you want.

Script pack imports the following namespaces into your script (no need to do using for them):

  • NUnit.Framework
  • NUnit.Core
  • System.Reflection

scriptcs-nunit's People

Contributors

filipw avatar

Stargazers

Ryan Jackson avatar Christoffer Bo Petersen avatar Matt Hersh avatar  avatar Vaibhav avatar Glenn Block avatar

Watchers

James Cloos avatar  avatar Ryan Jackson avatar

Forkers

dhaneshkk

scriptcs-nunit's Issues

Following the Readme leeds to an `ERROR: Assembly not found.`

When trying out this package using the instructions found in the Readme running

scriptcs start.csx -debug

gives to the following output:

ERROR: Assembly not found.

Running the nunit-runner sample from the scriptcs-samples repository gives the same result.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.