Home > Code Generation, Testing > Code Templates – xUnit testing

Code Templates – xUnit testing

October 29th, 2012

A list of code templates specific to the xUnit unit test framework. The meaning of the text commands in bold can be seen in the corresponding topic.

Template

Expansion

tc public class «Caret»«Field(TestClsas)»«BlockAnchor»
{
 [Fact]
 public void «Field(TestMethod()
 {
            «Marker»«Target»
 }
}
tf «?Set(FixtureType,«?Paste»)»public class «Caret»«Field(FixtureTests)»«BlockAnchor» : IUseFixture<«Link(«?Get(FixtureType)»)»>
{
  private «Link(«?Get(FixtureType)»)» _Fixture;
            public void SetFixture(«Link(«?Get(FixtureType)»)» fixture)
            {
                        _Fixture = fixture;
            }
}

Or

«?Set(FixtureType,TestFixturepublic class «FieldStart»«Caret»«Link(«?Get(FixtureType)»)»«BlockAnchor»«FieldEnd» : IDisposable
{
  public «Link(«?Get(FixtureType)»)»()
  {
            «Target»
  }
 
  public void Dispose()
  {
            «FinalTarget»
  }
}
public class «Caret»«Field(FixtureTests)»«BlockAnchor» : IUseFixture<«Link(«?Get(FixtureType)»)»>
{
  private «Link(«?Get(FixtureType)»)» _Fixture;
            public void SetFixture(«Link(«?Get(FixtureType)»)» fixture)
            {
                        _Fixture = fixture;
            }
}

tm [Fact]
public void «Caret»«Field(TestMethod)»«BlockAnchor»()
{
            «Marker»«Target»
}

Asserts

Template

Expansion

ac Assert.Contains(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)«?Semicolon»
acc Assert.Contains(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value, «Field(comparer, Comparer)«?Semicolon»
adnc/anc Assert.DoesNotContain(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value)«?Semicolon»
adncc/ancc Assert.DoesNotContain(«Caret»«Field(expected,Expected value)»«BlockAnchor», «Field(actual,Actual value, «Field(comparer, Comparer)«?Semicolon»
adntr Assert.DoesNotThrow(«Caret»«Field(value)» «BlockAnchor»)«?Semicolon»
ae Assert.Equal(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value);
ae0 Assert.Equal(0, «Caret»«?Paste»«BlockAnchor»);

Or

Assert.Equal(0, «Caret»);

ae1 Assert.Equal(1, «Caret»«?Paste»«BlockAnchor»);

Or

Assert.Equal(1, «Caret»);

aec Assert.Equal(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value, «Field(comparer, Comparer)«?Semicolon»
aem Assert.Empty(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
af Assert.False(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
aiaf Assert.IsAssignableFrom(«Caret»«Field(value)» «BlockAnchor»)«?Semicolon»
aint Assert.IsNotType(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
air Assert.InRange(«Caret»«Field(actual,The actual value to be evalua)»«BlockAnchor», «Field(low,The (inclusive) low value of the range, «Field(high,The (inclusive) high value of the range);«FinalTarget»
airc Assert.InRange(«Caret»«Field(actual,The actual value to be evalua)»«BlockAnchor», «Field(low,The (inclusive) low value of the range, «Field(high,The (inclusive) high value of the range, «Field(comparer,The comparer used to evaluate the value’s range);«FinalTarget»
ait Assert.IsType(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
an Assert.Null(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
ane Assert.NotEqual(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value);
anec Assert.NotEqual(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value, «Field(comparer, Comparer)«?Semicolon»
anem Assert.NotEmpty(«Caret»«Field(value)»«BlockAnchor»)«?Semicolon»
anir Assert.NotInRange(«Caret»«Field(actual,The actual value to be evalua)»«BlockAnchor», «Field(low,The (inclusive) low value of the range, «Field(high,The (inclusive) high value of the range);«FinalTarget»
anirc Assert.NotInRange(«Caret»«Field(actual,The actual value to be evalua)»«BlockAnchor», «Field(low,The (inclusive) low value of the range, «Field(high,The (inclusive) high value of the range, «Field(comparer,The comparer used to evaluate the value’s range);«FinalTarget»
ann Assert.NotNull(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
ans Assert.NotSame(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)«?Semicolon»
as Assert.Same(«Caret»«Field(expected,Expected value)» «BlockAnchor», «Field(actual,Actual value)«?Semicolon»
at Assert.True(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»
atr Assert.Throws(«Caret»«Field(value)»«BlockAnchor») «?Semicolon»

Attributes

Template

Expansion

[ai [AssumeIdentity(«Caret»«Field(Name,The role’s name)»«BlockAnchor»)]«FinalTarget»
[ar [AutoRollbackAttribute]«Caret»
[cd [ClassData(«Caret»«Field(Type,The class that provides the data)»«BlockAnchor»)]«FinalTarget»
[ed [ExcelData(«Caret»«Field(FileName,The filename of the XLS spreadsheet file.)»«BlockAnchor», «Field(SelectStatement,The SELECT statement that returns the data for the theory)]«FinalTarget»
[f [Fact]«Caret»
[fc [FreezeClock(«Caret»«Field(year,The frozen year)»«BlockAnchor», «Field(month,The frozen month, «Field(day,The frozen day)]«FinalTarget»
[id [InlineData(«Caret»«Field(DataValues,The data values to pass to the theory)»«BlockAnchor»)]«FinalTarget»
[odd [OleDbData(«Caret»«Field(connectionString,The OLEDB connection string to the data)»«BlockAnchor», «Field(selectStatement,The SELECT statement used to return the data for the theory)]«FinalTarget»
[pd [PropertyData(«Caret»«Field(PropertyName,The name of the public static property on the test class that will provide the test data)»«BlockAnchor»)]«FinalTarget»
[rw [RunWith(«Caret»«FieldStart(Type of command)»«Paste»«FieldEnd» «BlockAnchor»)]«FinalTarget»

Or

[RunWith(«Caret»«Field(CommandType, Type of command)»«BlockAnchor»)]«FinalTarget»

[ssd [SqlServerData(«Caret»«Field(serverName,The server name of the Microsoft SQL Server)»«BlockAnchor», «Field(databaseName,The database name, «Field(selectStatement,The SQL SELECT statement to return the data for the data theory)]«FinalTarget»
[t [Trait(«Caret»«Field(name,The trait name)»«BlockAnchor»,«Field(value,The trait value)]«FinalTarget»
[th [Theory]«Caret»
[tr [Trace]«Caret»

Namespaces

Template

Expansion

ux/uxu using Xunit;
uxe/uxue using Xunit.Extensions;
uxs/uxus using Xunit.Sdk;
—–
Products: CodeRush Pro
Versions: 12.1 and up
VS IDEs: 2008 and up
Updated: Oct/29/2012
ID: C212

Similar Posts: