为NUnit制作Visual Studio模板

为NUnit制作Visual Studio模板

创建NUnitTestClass.vstemplate文件

01 <VSTemplate Type="Item" Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
02   <TemplateData>
03     <Name>Nunit Test Class</Name>
04     <Description>NUnit Test Class Template</Description>
05     <DefaultName>NUnitTestClass</DefaultName>
06     <ProjectType>CSharp</ProjectType>
07     <Icon>NUnitTestClass.ico</Icon>
08   </TemplateData>
09   <TemplateContent>
10     <ProjectItem TargetFileName="$fileinputname$.cs" ReplaceParameters="true">
11       NUnitTestClass.cs
12     </ProjectItem>
13   </TemplateContent>
14 </VSTemplate>

创建NUnitTestClass.cs文件

01 using System;
02 using System.Collections.Generic;
03 using System.Text;
04 using NUnit.Framework;
05 using Rhino.Mocks;
06 using $rootnamespace$;
07   
08 namespace $rootnamespace$.Test
09 {
10     [TestFixture]
11     public class $safeitemname$
12     {
13         [Test]
14         public void TestMethod()
15         {
16             MockRepository mocks = new MockRepository();
17             IDependency dependency = mocks.StrictMock<IDEPENDENCY>();
18   
19             using (mocks.Record())
20             {
21                 dependency.Expect(x => x.Method("para")).Return("result");
22             }
23   
24             Subject subjectUnderTest;
25             using (mocks.Playback())
26             {
27                 subjectUnderTest = new Subject(dependency);
28                 subjectUnderTest.DoWork();
29             }
30   
31             Assert.That(subjectUnderTest.WorkDone, Is.True);
32         }
33     }
34 }
35 </IDEPENDENCY>

创建NUnitTestClass.ico文件

|\ || ||| || \|+-+

制作NunitTestClass.zip文件

把这三个文件

  1. NUnitTestClass.vstemplate
  2. NUnitTestClass.cs
  3. NUnitTestClass.ico

压缩成zip文件(不要建文件夹):

  • NUnitTestClass.zip

再把zip文件, 放到E:\My Documents\Visual Studio 2010\Templates\ItemTemplates\Visual C#中.

Visual Studio中, Add -> New Item... 就多了个 "NUnit Test Class" 模板.

[完]

你可能感兴趣的:(IO)