forked from xunit/xunit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now test collections can be specified on per test method basis.
- Loading branch information
1 parent
7737458
commit 7fa0f32
Showing
12 changed files
with
140 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/xunit.execution/Sdk/Frameworks/CollectionPerMethodTestCollectionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit.Abstractions; | ||
|
||
namespace Xunit.Sdk | ||
{ | ||
/// <summary> | ||
/// Implementation of <see cref="IXunitTestCollectionFactory"/> which creates a new test | ||
/// collection for each test method that isn't decorated with <see cref="CollectionAttribute"/>. | ||
/// </summary> | ||
public class CollectionPerMethodTestCollectionFactory : IXunitTestCollectionFactory | ||
{ | ||
readonly Dictionary<string, ITypeInfo> collectionDefinitions; | ||
readonly ConcurrentDictionary<string, ITestCollection> testCollections = new ConcurrentDictionary<string, ITestCollection>(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CollectionPerMethodTestCollectionFactory" /> class. | ||
/// </summary> | ||
/// <param name="assemblyInfo">The assembly.</param> | ||
public CollectionPerMethodTestCollectionFactory(IAssemblyInfo assemblyInfo) | ||
: this(assemblyInfo, MessageAggregator.Instance) { } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="CollectionPerMethodTestCollectionFactory" /> class. | ||
/// </summary> | ||
/// <param name="assemblyInfo">The assembly info.</param> | ||
/// <param name="messageAggregator">The message aggregator used to report <see cref="EnvironmentalWarning"/> messages.</param> | ||
public CollectionPerMethodTestCollectionFactory(IAssemblyInfo assemblyInfo, IMessageAggregator messageAggregator) | ||
{ | ||
collectionDefinitions = TestCollectionFactoryHelper.GetTestCollectionDefinitions(assemblyInfo, messageAggregator); | ||
} | ||
|
||
/// <inheritdoc/> | ||
public string DisplayName | ||
{ | ||
get { return "collection-per-method"; } | ||
} | ||
|
||
ITestCollection CreateCollection(string name) | ||
{ | ||
ITypeInfo definitionType; | ||
collectionDefinitions.TryGetValue(name, out definitionType); | ||
return new XunitTestCollection { CollectionDefinition = definitionType, DisplayName = name }; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ITestCollection Get(IMethodInfo testMethod) | ||
{ | ||
string collectionName; | ||
var collectionAttribute = testMethod.GetCustomAttributes(typeof(CollectionAttribute)).SingleOrDefault(); | ||
|
||
if (collectionAttribute == null) | ||
collectionName = "Test collection for " + testMethod.Type.Name + "." + testMethod.Name; | ||
else | ||
collectionName = (string)collectionAttribute.GetConstructorArguments().First(); | ||
|
||
return testCollections.GetOrAdd(collectionName, CreateCollection); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.