Visual Studio project & item templates and snippets
Перейти к файлу
Terje Sandstrom f66374fdcf
Merge pull request #53 from nunit/update
Update NUnit to 3.12 and Adapter to 3.17
2020-07-13 22:34:56 +02:00
nunit.templates Updated to NUnit 3.12 and adapter 3.17 2020-07-13 22:21:17 +02:00
nunit.tests.core.csharp Updated to NUnit 3.12 and adapter 3.17 2020-07-13 22:21:17 +02:00
nunit.tests.csharp Updated to NUnit 3.12 and adapter 3.17 2020-07-13 22:21:17 +02:00
nunit.tests.sdkstyle.csharp Updated to NUnit 3.12 and adapter 3.17 2020-07-13 22:21:17 +02:00
nunit.tests.vb Updated to NUnit 3.12 and adapter 3.17 2020-07-13 22:21:17 +02:00
xamarin Changes csprojs 2019-02-28 12:36:05 +01:00
.editorconfig Updated spaces in vsixmanifest 2019-03-05 17:40:47 +01:00
.gitattributes Added test fixture and test method code snippets 2015-10-17 19:33:07 -04:00
.gitignore Move snippets under 'NUnit' rather than 'Test' 2016-12-22 21:05:27 +00:00
LICENSE Switch copyright to NUnit Project 2017-06-16 22:16:56 -04:00
README.md Fixing comments 2019-03-10 19:52:03 +01:00
Rebracer.xml Suggest types 2016-12-24 09:13:13 -05:00
nunit.png Updated templates for sdk style and core 2019-03-09 17:42:59 +01:00
nunit.templates.sln Updated to work with VS2017 and VS2019. 2019-03-03 20:15:46 +01:00

README.md

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-2019 from the Visual Studio Gallery or from the GitHub Releases page.

Content

The project currently provides the following templates.

Project Templates

Template Platform Language Project Type
NUnit 3 Unit Test Project Desktop C# Traditional Style 3
NUnit 3 Unit Test Project Desktop C# Sdk Style
NUnit 3 Unit Test Project Desktop .NET Core C# SDK Style
NUnit 3 Unit Test Project Desktop Visual Basic Traditional Style 3
NUnit 3 Unit Test Project Xamarin Android 1 C# Traditional Style
NUnit 3 Unit Test Project Xamarin iOS 1 C# Traditional Style
NUnit 3 Unit Test Project Xamarin UWP 1,2 C# Traditional Style
  1. Requires Xamarin for Visual Studio be installed.
  2. Requires the Windows 10 SDK be installed.
  3. Legacy csproj format

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 Comment
Test Fixture ntestfixture C#
Test Method ntest C#
Test Case ntestcase C#
Test Case Source ntestcasesource C# Form 1
Test Case Source ntestcasesource2 C# Form 2
Test Case Source ntestcasesource3 C# Form 3
Test Case Source ntestcasesource4 C# Form 3 with testdata
Assert.Multiple nmultiple C# Surround snippet

Note: "Form": Refer to documentation for details

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 (Not needed, now included as nuget package) - 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