Random programming things I'd want to remember

Showing posts with label shortcut. Show all posts
Showing posts with label shortcut. Show all posts

Wednesday, January 17, 2018

Visual Studio snippet for a TestMethod with a proper naming convention (naming convention was proposed by Roy Osherove)

Here it is, see this post for details on how to import it into your Visual Studio. Enjoy!

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Test method with a naming convention</Title>
      <Author>Roy Osherove, yevgeller</Author>
      <Description>Test method with the following naming convention: method under testing, condition, and expected results. The naming convention was taken from Roy Osherove's book "The Art of Unit Testing"</Description>
      <Shortcut>testmc</Shortcut>
    </Header>
    <Snippet>
      <Imports>
        <Import>
          <Namespace>
            Microsoft.VisualStudio.TestTools.UnitTesting;
          </Namespace>
        </Import>
      </Imports>
      <Declarations>
        <Literal>
          <ID>NameOfMethodUnderTest</ID>
          <ToolTip>Replace with the method that you want to test</ToolTip>
          <Default>YourMethod</Default>
        </Literal>
        <Literal>
          <ID>ConditionYouAreTesting</ID>
          <ToolTip>Condition that you want to test</ToolTip>
          <Default>IsNull</Default>
        </Literal>
        <Literal>
          <ID>ExpectedResult</ID>
          <ToolTip>The result that you expect</ToolTip>
          <Default>NullArgumentException</Default>
        </Literal>
      </Declarations>
        <Code Language="csharp">
          <![CDATA[          
          [TestMethod]
          public void $NameOfMethodUnderTest$_$ConditionYouAreTesting$_$ExpectedResult$()
          {

          }
          ]]>
        </Code>
      </Snippet>
  </CodeSnippet>
</CodeSnippets>