Permalink
Browse files

Xunit 2 support

  • Loading branch information...
Jim Counts
Jim Counts committed Mar 23, 2015
1 parent 9dd395e commit f9f3f1f4fb28db6bbfafc518ba2d07b7d179f544
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
<Import Project="..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props" Condition="Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E9BD0B96-01C4-4B25-ADFD-3A630970D267}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ApprovalTests.Xunit2</RootNamespace>
<AssemblyName>ApprovalTests.Xunit2</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<NuGetPackageImportStamp>0a061e67</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions">
<HintPath>..\packages\xunit.abstractions.2.0.0\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert">
<HintPath>..\packages\xunit.assert.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core">
<HintPath>..\packages\xunit.extensibility.core.2.0.0\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Namer\XunitStackTraceNamerTest.cs" />
<Compile Include="Namer\XunitTheoryStackTraceParserTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reporters\NonNUnitReporterTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ApprovalTests\ApprovalTests.csproj">
<Project>{F70C9A76-F797-4167-8178-14821F8634BC}</Project>
<Name>ApprovalTests</Name>
</ProjectReference>
<ProjectReference Include="..\ApprovalUtilities\ApprovalUtilities.csproj">
<Project>{E9683C33-7A71-4776-B7C9-E89C565AC16B}</Project>
<Name>ApprovalUtilities</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
<Error Condition="!Exists('..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.core.2.0.0\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid+Xamarin.iOS\xunit.core.props'))" />
<Error Condition="!Exists('..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,18 @@

Could Not Detect Test Framework
Either:
1) Optimizer Inlined Test Methods
Solutions:
a) Add [MethodImpl(MethodImplOptions.NoInlining)]
b) Set Build->Opitmize Code to False
& Build->Advanced->DebugInfo to Full
or
2) Approvals is not set up to use your test framework.
It currently supports [NUnit, MsTest, MbUnit, xUnit.net, xUnit.extensions, Machine.Specifications (MSpec)]
Solution:
To add one use ApprovalTests.Namers.StackTraceParsers.StackTraceParser.AddParser() method to add implementation of ApprovalTests.Namers.StackTraceParsers.IStackTraceParser with support for your testing framework.
To learn how to implement one see http://blog.approvaltests.com/2012/01/creating-namers.html
@@ -0,0 +1,71 @@
namespace ApprovalTests.Xunit2.Namer
{
using ApprovalTests.Namers;
using ApprovalTests.Namers.StackTraceParsers;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using global::Xunit;
public class XunitStackTraceNamerTest
{
[Fact]
public async Task AsyncTestApprovalName()
{
var name = new UnitTestFrameworkNamer().Name;
var path = new UnitTestFrameworkNamer().SourcePath;
await AnAsyncMethod();
Assert.Equal("XunitStackTraceNamerTest.AsyncTestApprovalName", name);
Assert.True(File.Exists(path + "\\XunitStackTraceNamerTest.cs"));
}
[Fact]
public async Task FullAsyncTest()
{
await AnAsyncMethod();
Approvals.Verify("Async");
}
[Fact(Skip = "This is Hard")]
//[Fact]
public async Task ProperFullAsyncTest()
{
await Task.Delay(10);
// This is the stack trace, and needs to do MAGIC!
// at ApprovalTests.Xunit.Namer.XunitStackTraceNamerTest.<ProperFullAsyncTest>d__c.MoveNext()
Approvals.Verify("Async with Delay");
}
[Fact]
public void TestApprovalName()
{
var name = new UnitTestFrameworkNamer().Name;
Assert.Equal("XunitStackTraceNamerTest.TestApprovalName", name);
}
[Fact]
public void TestApprovalNamerFailureMessage()
{
var parser = new StackTraceParser();
var exception = Assert.Throws<Exception>(() => parser.Parse(new StackTrace(6)));
Approvals.Verify(exception.Message);
}
private static Task AnAsyncMethod()
{
return Task.FromResult(default(object));
}
private void AssertEquals<T>(string typeName)
{
Type instance = Type.GetType(typeName, false);
Assert.Equal(typeof(T), instance);
}
}
}
@@ -0,0 +1,41 @@
namespace ApprovalTests.Xunit2.Namer
{
using ApprovalTests.Namers;
using global::Xunit;
public class XunitTheoryStackTraceParserTest
{
[Theory]
[InlineData]
public void TestApprovalName()
{
var name = new UnitTestFrameworkNamer().Name;
Assert.Equal("XunitTheoryStackTraceParserTest.TestApprovalName", name);
}
[Theory]
[InlineData("file1.txt")]
[InlineData("file2.txt")]
public void TestApprovalNameWithAdditionalInformation(string fileName)
{
using (ApprovalResults.ForScenario(fileName))
{
var name = new UnitTestFrameworkNamer().Name;
Assert.Equal("XunitTheoryStackTraceParserTest.TestApprovalNameWithAdditionalInformation.ForScenario." + fileName,
name);
}
}
[Theory]
[InlineData("File \\;:/\"1.txt")]
public void TestInvalidCharacters(string fileName)
{
using (ApprovalResults.ForScenario(fileName))
{
var name = new UnitTestFrameworkNamer().Name;
Assert.Equal("XunitTheoryStackTraceParserTest.TestInvalidCharacters.ForScenario.File _;___1.txt", name);
}
}
}
}
@@ -0,0 +1,39 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
using ApprovalTests.Reporters;
[assembly: AssemblyTitle("ApprovalTests.Xunit2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ApprovalTests.Xunit2")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
[assembly: UseReporter(typeof(DiffReporter))]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("77603ee0-d9b9-4de8-b850-8dfa013b6766")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,5 @@
Assert.Equal() Failure
↓ (pos 5)
Expected: Hello
Actual: Hello2
↑ (pos 5)
@@ -0,0 +1,32 @@
namespace ApprovalTests.Xunit2.Reporters
{
using ApprovalTests.Reporters;
using ApprovalUtilities.Utilities;
using global::Xunit;
public class NonNUnitReporterTest
{
[Fact]
public void TestNunitIsNotWorkingFromXUnit()
{
Approvals.SetCaller();
Assert.False(NUnitReporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
}
[Fact]
public void TestXunitIsWorking()
{
Approvals.SetCaller();
Assert.True(XUnitReporter.INSTANCE.IsWorkingInThisEnvironment("default.txt"));
}
[Fact]
public void TestXunitReporterIsWorking()
{
var e = ExceptionUtilities.GetException(() => XUnit2Reporter.INSTANCE.AssertEqual("Hello", "Hello2"));
Approvals.Verify(e.Message);
}
}
}
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xunit" version="2.0.0" targetFramework="net45" />
<package id="xunit.abstractions" version="2.0.0" targetFramework="net45" />
<package id="xunit.assert" version="2.0.0" targetFramework="net45" />
<package id="xunit.core" version="2.0.0" targetFramework="net45" />
<package id="xunit.extensibility.core" version="2.0.0" targetFramework="net45" />
<package id="xunit.runner.visualstudio" version="2.0.0" targetFramework="net45" />
</packages>
View
@@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApprovalTests.MachineSpecif
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApprovalUtilities.Net45", "ApprovalUtilities.Net45\ApprovalUtilities.Net45.csproj", "{C4BEE6F7-448B-43D6-A9C3-17273C94B0E6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApprovalTests.Xunit2", "ApprovalTests.Xunit2\ApprovalTests.Xunit2.csproj", "{E9BD0B96-01C4-4B25-ADFD-3A630970D267}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -101,6 +103,10 @@ Global
{C4BEE6F7-448B-43D6-A9C3-17273C94B0E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4BEE6F7-448B-43D6-A9C3-17273C94B0E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4BEE6F7-448B-43D6-A9C3-17273C94B0E6}.Release|Any CPU.Build.0 = Release|Any CPU
{E9BD0B96-01C4-4B25-ADFD-3A630970D267}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E9BD0B96-01C4-4B25-ADFD-3A630970D267}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E9BD0B96-01C4-4B25-ADFD-3A630970D267}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E9BD0B96-01C4-4B25-ADFD-3A630970D267}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -154,12 +154,14 @@
<Compile Include="Namers\NamerFactory.cs" />
<Compile Include="Namers\StackTraceParsers\AttributeStackTraceParser.cs" />
<Compile Include="Namers\UnitTestFrameworks\MSpecStackTraceParser.cs" />
<Compile Include="Namers\UnitTestFrameworks\XUnit2TheoryStackTraceParser.cs" />
<Compile Include="Namers\UnitTestFrameworks\XUnitStackTraceParser.cs" />
<Compile Include="Namers\UnitTestFrameworks\XUnitTheoryStackTraceParser.cs" />
<Compile Include="Namers\UseApprovalSubdirectoryAttribute.cs" />
<Compile Include="Reporters\BeyondCompareReporter.cs" />
<Compile Include="Reporters\BeyondCompare4Reporter.cs" />
<Compile Include="Reporters\IgnoreLineEndingsAttribute.cs" />
<Compile Include="Reporters\XUnit2Reporter.cs" />
<Compile Include="Scrubber\HtmlScrubbers.cs" />
<Compile Include="Scrubber\PdfScrubber.cs" />
<Compile Include="Persistence\DatabaseApprovals.cs" />
Oops, something went wrong.

0 comments on commit f9f3f1f

Please sign in to comment.