本文整理汇总了C#中ITestMethod类的典型用法代码示例。如果您正苦于以下问题:C# ITestMethod类的具体用法?C# ITestMethod怎么用?C# ITestMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITestMethod类属于命名空间,在下文中一共展示了ITestMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Discover
public IEnumerable<IXunitTestCase> Discover (ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault ();
if (testMethod.Method.GetParameters ().Any ()) {
return new IXunitTestCase[] {
new ExecutionErrorTestCase (messageSink, defaultMethodDisplay, testMethod, "[VsixFact] methods are not allowed to have parameters.")
};
} else {
var vsVersions = VsVersions.GetFinalVersions(testMethod.GetComputedProperty<string[]>(factAttribute, SpecialNames.VsixAttribute.VisualStudioVersions));
// Process VS-specific traits.
var suffix = testMethod.GetComputedArgument<string>(factAttribute, SpecialNames.VsixAttribute.RootSuffix) ?? "Exp";
var newInstance = testMethod.GetComputedArgument<bool?>(factAttribute, SpecialNames.VsixAttribute.NewIdeInstance);
var timeout = testMethod.GetComputedArgument<int?>(factAttribute, SpecialNames.VsixAttribute.TimeoutSeconds).GetValueOrDefault(XunitExtensions.DefaultTimeout);
var testCases = new List<IXunitTestCase>();
// Add invalid VS versions.
testCases.AddRange (vsVersions
.Where (v => !VsVersions.InstalledVersions.Contains (v))
.Select (v => new ExecutionErrorTestCase (messageSink, defaultMethodDisplay, testMethod,
string.Format ("Cannot execute test for specified {0}={1} because there is no VSSDK installed for that version.", SpecialNames.VsixAttribute.VisualStudioVersions, v))));
testCases.AddRange (vsVersions
.Where (v => VsVersions.InstalledVersions.Contains (v))
.Select (v => new VsixTestCase (messageSink, defaultMethodDisplay, testMethod, v, suffix, newInstance, timeout)));
return testCases;
}
}
示例2: AssignTestExecutionMethodInfo
public static void AssignTestExecutionMethodInfo(this TestExecutionMethod testExecutionMethod, ITestMethod testMethod)
{
var methodInfo = testMethod.Method;
testExecutionMethod.NamespaceName = methodInfo.ReflectedType.Namespace;
testExecutionMethod.ClassName = methodInfo.ReflectedType.ClassNameIncludingParentsIfNested();
testExecutionMethod.MethodName = testMethod.Name;
}
示例3: Discover
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var defaultMethodDisplay = discoveryOptions.MethodDisplayOrDefault();
return factAttribute.GetNamedArgument<string>("Skip") != null
? new[] { new XunitTestCase(_diagnosticMessageSink, defaultMethodDisplay, testMethod) }
: new XunitTestCase[] { new ScenarioTestCase(_diagnosticMessageSink, defaultMethodDisplay, testMethod) };
}
示例4: BenchmarkTestCaseBase
protected BenchmarkTestCaseBase(
string variation,
IMessageSink diagnosticMessageSink,
ITestMethod testMethod,
object[] testMethodArguments)
: base(diagnosticMessageSink, TestMethodDisplay.Method, testMethod, null)
{
// Override display name to avoid getting info about TestMethodArguments in the
// name (this is covered by the concept of Variation for benchmarks)
var name = TestMethod.Method.GetCustomAttributes(typeof(FactAttribute))
.First()
.GetNamedArgument<string>("DisplayName") ?? BaseDisplayName;
TestMethodName = name;
DisplayName = $"{name} [Variation: {variation}]";
DiagnosticMessageSink = diagnosticMessageSink;
Variation = variation;
var methodArguments = new List<object> { MetricCollector };
if (testMethodArguments != null)
{
methodArguments.AddRange(testMethodArguments);
}
TestMethodArguments = methodArguments.ToArray();
}
示例5: KuduXunitTheoryTestCase
public KuduXunitTheoryTestCase(IMessageSink diagnosticMessageSink,
TestMethodDisplay defaultMethodDisplay,
ITestMethod testMethod,
IAttributeInfo testAttribute)
: base(diagnosticMessageSink, defaultMethodDisplay, testMethod)
{
}
示例6:
public IEnumerable<IXunitTestCase> Discover
( ITestFrameworkDiscoveryOptions discoveryOptions
, ITestMethod testMethod
, IAttributeInfo factAttribute
)
{
var inv = InvariantTestCase.InvariantFromMethod(testMethod);
return
inv == null
? new[]
{ new InvariantTestCase
( MessageSink
, TestMethodDisplay.Method
, testMethod
, null
)
}
: inv.AsSeq().Select
( i =>
new InvariantTestCase
( MessageSink
, TestMethodDisplay.Method
, testMethod
, i
)
);
}
示例7: UnitTestMethodContainer
/// <summary>
/// Initializes dispatcher-stack attaching method container work item.
/// </summary>
/// <param name="testHarness">Test harness.</param>
/// <param name="instance">Test instance.</param>
/// <param name="method">Method reflection object.</param>
/// <param name="testMethod">Test method metadata.</param>
/// <param name="granularity">Granularity of test.</param>
public UnitTestMethodContainer(UnitTestHarness testHarness, object instance, MethodInfo method, ITestMethod testMethod, TestGranularity granularity)
: base(instance, method, testMethod)
{
_granularity = granularity;
_harness = testHarness as UnitTestHarness;
_testMethod = testMethod;
}
示例8: BenchmarkTestCase
public BenchmarkTestCase(
int iterations,
int warmupIterations,
string variation,
IMessageSink diagnosticMessageSink,
ITestMethod testMethod,
object[] testMethodArguments)
: base(diagnosticMessageSink, Xunit.Sdk.TestMethodDisplay.Method, testMethod, null)
{
// Override display name to avoid getting info about TestMethodArguments in the
// name (this is covered by the concept of Variation for benchmarks)
var suppliedDisplayName = TestMethod.Method.GetCustomAttributes(typeof(FactAttribute))
.First()
.GetNamedArgument<string>("DisplayName");
_diagnosticMessageSink = diagnosticMessageSink;
DisplayName = suppliedDisplayName ?? BaseDisplayName;
Variation = variation;
Iterations = iterations;
WarmupIterations = warmupIterations;
var methodArguments = new List<object> { MetricCollector };
if (testMethodArguments != null)
{
methodArguments.AddRange(testMethodArguments);
}
TestMethodArguments = methodArguments.ToArray();
}
示例9: Discover
public override IEnumerable<IXunitTestCase> Discover(
ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
MethodInfo testMethodInfo = testMethod.Method.ToRuntimeMethod();
string conditionMemberName = factAttribute.GetConstructorArguments().FirstOrDefault() as string;
MethodInfo conditionMethodInfo;
if (conditionMemberName == null ||
(conditionMethodInfo = LookupConditionalMethod(testMethodInfo.DeclaringType, conditionMemberName)) == null)
{
return new[] {
new ExecutionErrorTestCase(
_diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
testMethod,
GetFailedLookupString(conditionMemberName))
};
}
IEnumerable<IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute);
if ((bool)conditionMethodInfo.Invoke(null, null))
{
return testCases;
}
else
{
string skippedReason = "\"" + conditionMemberName + "\" returned false.";
return testCases.Select(tc => new SkippedTestCase(tc, skippedReason));
}
}
示例10: FindTestsForMethod
/// <summary>
/// Finds the tests on a test method.
/// </summary>
/// <param name="testMethod">The test method.</param>
/// <param name="includeSourceInformation">Set to <c>true</c> to indicate that source information should be included.</param>
/// <param name="messageBus">The message bus to report discovery messages to.</param>
/// <param name="discoveryOptions">The options used by the test framework during discovery.</param>
/// <returns>Return <c>true</c> to continue test discovery, <c>false</c>, otherwise.</returns>
protected virtual bool FindTestsForMethod(ITestMethod testMethod, bool includeSourceInformation, IMessageBus messageBus, ITestFrameworkDiscoveryOptions discoveryOptions)
{
var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).FirstOrDefault();
if (factAttribute == null)
return true;
var testCaseDiscovererAttribute = factAttribute.GetCustomAttributes(typeof(XunitTestCaseDiscovererAttribute)).FirstOrDefault();
if (testCaseDiscovererAttribute == null)
return true;
var args = testCaseDiscovererAttribute.GetConstructorArguments().Cast<string>().ToList();
var discovererType = SerializationHelper.GetType(args[1], args[0]);
if (discovererType == null)
return true;
var discoverer = GetDiscoverer(discovererType);
if (discoverer == null)
return true;
foreach (var testCase in discoverer.Discover(discoveryOptions, testMethod, factAttribute))
if (!ReportDiscoveredTestCase(testCase, includeSourceInformation, messageBus))
return false;
return true;
}
示例11: ScenarioResult
/// <summary>
/// Creates a result record.
/// </summary>
/// <param name="method">Test method metadata object.</param>
/// <param name="testClass">Test class metadata object.</param>
/// <param name="result">Test result object.</param>
/// <param name="exception">Exception instance, if any.</param>
public ScenarioResult(ITestMethod method, ITestClass testClass, TestOutcome result, Exception exception)
{
TestClass = testClass;
TestMethod = method;
Exception = exception;
Result = result;
}
示例12: TestMethodManager
/// <summary>
/// Constructor for a test method manager, which handles executing a single test method
/// for a unit test provider.
/// </summary>
/// <param name="testHarness">The unit test harness object.</param>
/// <param name="testClass">The test class metadata object.</param>
/// <param name="testMethod">The test method metadata object.</param>
/// <param name="instance">The test class instance.</param>
/// <param name="provider">The unit test provider.</param>
public TestMethodManager(UnitTestHarness testHarness, ITestClass testClass, ITestMethod testMethod, object instance, IUnitTestProvider provider)
: base(testHarness, provider)
{
_testClass = testClass;
_testMethod = testMethod;
_instance = instance;
}
示例13: Discover
public virtual IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var variations = testMethod.Method
.GetCustomAttributes(typeof(BenchmarkVariationAttribute))
.ToDictionary(
a => a.GetNamedArgument<string>(nameof(BenchmarkVariationAttribute.VariationName)),
a => a.GetNamedArgument<object[]>(nameof(BenchmarkVariationAttribute.Data)));
if (!variations.Any())
{
variations.Add("Default", new object[0]);
}
var tests = new List<IXunitTestCase>();
foreach (var variation in variations)
{
tests.Add(new BenchmarkTestCase(
factAttribute.GetNamedArgument<int>(nameof(BenchmarkAttribute.Iterations)),
factAttribute.GetNamedArgument<int>(nameof(BenchmarkAttribute.WarmupIterations)),
variation.Key,
_diagnosticMessageSink,
testMethod,
variation.Value));
}
return tests;
}
示例14: MethodContainer
/// <summary>
/// Constructs a new method container.
/// </summary>
/// <param name="instance">An instance of the method's type.</param>
/// <param name="method">The method reflection object.</param>
/// <param name="testMethod">The test method.</param>
public MethodContainer(object instance, MethodInfo method, ITestMethod testMethod)
: base()
{
_methodTask = new MethodInvokeWorkItem(instance, method, testMethod);
_methodInfo = method;
_method = testMethod;
}
示例15: Discover
public override IEnumerable<IXunitTestCase> Discover(
ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
string[] conditionMemberNames = factAttribute.GetConstructorArguments().FirstOrDefault() as string[];
IEnumerable<IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute);
return ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, conditionMemberNames);
}