Skip to content

Latest commit

 

History

History
121 lines (94 loc) · 6.6 KB

README.md

File metadata and controls

121 lines (94 loc) · 6.6 KB

NUnit Visual Studio Templates

Build status

An extension that adds Project and Item templates to Visual Studio along with Code Snippets to make unit testing with NUnit 3 easier. We currently only plan to add templates for NUnit 3, but will add templates for NUnit 2.6.4 if there is demand.

This project is build using SideWaffle, many thanks for their great work.

Download

You can download the extension for Visual Studio 2012-2017 from the Visual Studio Gallery or from the GitHub Releases page.

Content

The project currently provides the following templates.

Project Templates

Template Platform Language
NUnit 3 Unit Test Project Desktop C#
NUnit 3 Unit Test Project Desktop Visual Basic
NUnit 3 Unit Test Project Xamarin Android 1 C#
NUnit 3 Unit Test Project Xamarin iOS 1 C#
NUnit 3 Unit Test Project Xamarin UWP 1,2 C#
  1. Requires Xamarin for Visual Studio be installed.
  2. Requires the Windows 10 SDK be installed.

Item Templates

Template Language Description
NUnit Test Fixture C# An NUnit unit test class
NUnit Test Fixture Visual Basic An NUnit unit test class
NUnit SetUp Fixture C# Code that runs before and after all the tests in the assembly
NUnit SetUp Fixture Visual Basic Code that runs before and after all the tests in the assembly

Code Snippets

Snippet Shortcut Language
Test Fixture ntestfixture C#
Test Method ntest C#
Test Case ntestcase C#

Contributing

Don't see the template you need or your favorite code snippet? All you need to do is fork the repository, add it and create a pull request. We love help and contributions.

For information on how to add templates and snippets, head over to the SideWaffle Documentation.

There is also a great walkthrough on creating templates in the June 2015 MSDN Magazine.

Prerequisites

We highly recommend that you use the following extensions for Visual Studio when working on this project.

  • SideWaffle (Required) - Adds the templates and functionality you will need to work on this project.
  • Snippet Designer - Provides a friendly UI for editing code snippets.
  • EditorConfig - Configures tabs and spaces to the project defaults.
  • Rebracer - Configures code formating to the NUnit project defaults in Visual Studio.

Adding Project Templates

  • Add a new project that will serve as your template
  • Modify the project to ensure it builds and produces the correct output
  • Right click on the nunit.templates project and select Add | Add Template Reference (SideWaffle project).
  • Select your project from the dropdown and add it.
  • Your project will have two new files added, _Definitions\_project.vstemplate.xml and _preprocess.xml.
  • Edit both of these files using those from other projects as a reference.
  • Delete sw-file-icon.png from your project.
  • Copy nunit.png from nunit-tests.csharp into your project directory, but don't add it to your project.
  • Remove packages.config and edit the project file to remove all of your NuGet references.
  • Add NuGet packages to your vstemplate file. See the other vstemplate files and NuGet docs for more information.
  • If the NuGet package isn't already in the nunit.templates\Packages directory, you will have to add it, set it as Include in VSIX and add it to the vsixmanifest file.
  • Test your project template by compiling and running the project. This will open an experimental instance of Visual Studio with the extension installed for testing.
  • Once you are happy with your project, remove it from all build configurations.- Add your project template to README.md
  • Push your branch to GitHub and create a Pull Request

Adding Item Templates

  • Right-click on the ItemTemplates\Test folder in the nunit.templates project, Add | New Item... and add a SideWaffle Item Template. Don't worry about the name, it is not used
  • This will create a CSharp folder, rename it for your template
  • Add your source file into your new folder and set the Build Action in properties to Content
  • Replace your namespace with $rootnamespace$ and your class name with $safeitemname$
  • Four vstemplate files were created in a Definitions sub-folder. Delete any for languages your template does not support and then rename the remaining from *.vstemplat- to *.vstemplate
  • Fill in the vstemplate files using existing templates as a reference
  • Delete the readme.txt file and overwrite icon.png with an existing NUnit icon from another template.
  • Test your item template by compiling and running the project. This will open an experimental instance of Visual Studio with the extension installed for testing.
  • Add your item template to README.md
  • Push your branch to GitHub and create a Pull Request

Adding Code Snippets

  • In the language specific Snippets folder of the nunit.templates project, right click on the Test folder and Add | New item...*
  • Search for snippet and add a new Code Snippet
  • Make sure the build type for your new snippet is set to Content in the properties
  • Edit your snippet making sure to give it a unique shortcut. We are currently starting all NUnit snippets with the letter n
  • Test your snippet by compiling and running the project. This will open an experimental instance of Visual Studio with the extension installed for testing.
  • Add your snippet to README.md
  • Push your branch to GitHub and create a Pull Request