public SetUpTearDownDecoratorTestCase(ITestCase testCase, MethodInfo setUpMethod, MethodInfo tearDownMethod) : base(testCase) { this.setUpMethod = setUpMethod; this.tearDownMethod = tearDownMethod; }
public TestCaseWorker(ITestCase testCase, int index) { if (testCase == null) throw new ArgumentNullException("testCase"); this.testCase = testCase; this.index = index; }
/// <summary> /// Removes automation from a test case. /// </summary> public void RemoveAutomation(ITestCase testCase) { testCase.WorkItem.Open(); testCase.Implementation = null; testCase.CustomFields["Automation status"].Value = "Not Automated"; testCase.Save(); }
public TestFailed(ITestCase testCase, string testDisplayName, decimal executionTime, string output, string exceptionType, string message, string stackTrace) : base(testCase, testDisplayName, executionTime, output) { StackTrace = stackTrace; Message = message; ExceptionType = exceptionType; }
private static VsTestCase Convert( ITestCase testcase, string shortName, string fullyQualifiedName, bool uniquifyNames) { string uniqueName; if (uniquifyNames) uniqueName = string.Format("{0}({1})", fullyQualifiedName, testcase.UniqueID); else uniqueName = fullyQualifiedName; var result = new VsTestCase(); result.DisplayName = shortName; result.FullyQualifiedName = uniqueName; result.Id = GuidFromString(testcase.UniqueID); if (testcase.SourceInformation != null) { result.CodeFilePath = testcase.SourceInformation.FileName; result.LineNumber = testcase.SourceInformation.LineNumber; } return result; }
public bool SoSanh(string output, ITestCase testcase, out string message) { message = ""; string[] s1Lines = output.Split('\n'); string[] s2Lines = testcase.Output.Split('\n'); int i = 0; while (i < s1Lines.Length && i < s2Lines.Length) { if (SoSanhLine(s1Lines[i], s2Lines[i]) == false) { message = "SAI KẾT QUẢ 1"; return false; } i++; } while (i < s1Lines.Length) { if (!IsEmptyLine(s1Lines[i])) { message = "SAI KẾT QUẢ 2"; return false; } } while (i < s2Lines.Length) { if (!IsEmptyLine(s2Lines[i])) { message = "SAI KẾT QUẢ 3"; return false; } } message = "ĐÚNG KẾT QUẢ"; return true; }
private static string GetShortName(ITestCase tc) { var shortName = new StringBuilder(); var classFullName = tc.TestMethod.TestClass.Class.Name; var dotIndex = classFullName.LastIndexOf('.'); if (dotIndex >= 0) shortName.Append(classFullName.Substring(dotIndex + 1)); else shortName.Append(classFullName); shortName.Append("."); shortName.Append(tc.TestMethod.Method.Name); // We need to shorten the arguments list if it's long. Let's arbitrarily pick 50 characters. var argumentsIndex = tc.DisplayName.IndexOf('('); if (argumentsIndex >= 0 && tc.DisplayName.Length - argumentsIndex > 50) { shortName.Append(tc.DisplayName.Substring(argumentsIndex, 46)); shortName.Append("..."); shortName.Append(")"); } else if (argumentsIndex >= 0) shortName.Append(tc.DisplayName.Substring(argumentsIndex)); return shortName.ToString(); }
public bool Filter(IFixture fixture, ITestCase test) { foreach (string scope in scopes) if (test.Name.ToLower().StartsWith(scope.ToLower())) return true; return false; }
public override TestResult DoTest(ITestCase testCase, int testCasesNumber, bool singleton) { var result = new TestResult { Singleton = singleton, TestCasesNumber = testCasesNumber }; var sw = new Stopwatch(); var c = new ServiceContainer(); if (singleton) { sw.Start(); c = (ServiceContainer)testCase.SingletonRegister(c); sw.Stop(); } else { sw.Start(); c = (ServiceContainer)testCase.TransientRegister(c); sw.Stop(); } result.RegisterTime = sw.ElapsedMilliseconds; sw.Reset(); result.ResolveTime = DoResolve(sw, testCase, c, testCasesNumber, singleton); c.Dispose(); return result; }
/// <inheritdoc/> public SourceInformation GetSourceInformation(ITestCase testCase) { return new SourceInformation(); // TODO: Load DiaSession dynamically, since it's only available when running inside of Visual Studio. // Or look at the CCI2 stuff from the Rx framework: https://github.com/Reactive-Extensions/IL2JS/tree/master/CCI2/PdbReader }
public void ParseLine(string line) { if (line == null) return; if (!_testListingStarted && Regex.IsMatch(line, TestCaseRegex, RegexOptions.Singleline)) { _testListingStarted = true; _currentCase = _factory.BuildTestCase(_suite, line.TrimEnd('.').Trim()); _suite.AddTestCase(_currentCase); } else { if (Regex.IsMatch(line, TestCaseRegex, RegexOptions.Singleline)) { _currentCase = _factory.BuildTestCase(_suite, line.TrimEnd('.').Trim()); _suite.AddTestCase(_currentCase); } else if (_currentCase != null && line != string.Empty) { string testName = line.Trim(); ITest test = _factory.BuildTest(_currentCase, testName); _currentCase.AddTest(test); OnTestDiscovered(test); } } }
public ExpectedExceptionTestCase(ITestCase testCase,Type exceptionType) : base(testCase) { if (exceptionType == null) throw new ArgumentNullException("exceptionType"); this.exceptionType = exceptionType; }
public void FactAcceptanceTest() { string code = @" using System; using Xunit; namespace Namespace1 { public class Class1 { [Fact] [Trait(""Name!"", ""Value!"")] public void Trait() { } [Fact(Skip=""Skipping"")] public void Skipped() { } [Fact(DisplayName=""Custom Test Name"")] public void CustomName() { } } } namespace Namespace2 { public class OuterClass { public class Class2 { [Fact] public void TestMethod() { } } } }"; using (var assembly = CSharpAcceptanceTestV2Assembly.Create(code)) using (var controller = new TestableXunit2(assembly.FileName, null, true)) { var sink = new SpyMessageSink <IDiscoveryCompleteMessage>(); controller.Find(includeSourceInformation: false, messageSink: sink, discoveryOptions: TestFrameworkOptions.ForDiscovery()); sink.Finished.WaitOne(); ITestCase[] testCases = sink.Messages.OfType <ITestCaseDiscoveryMessage>().Select(tcdm => tcdm.TestCase).ToArray(); Assert.Equal(4, testCases.Length); ITestCase traitTest = Assert.Single(testCases, tc => tc.DisplayName == "Namespace1.Class1.Trait"); string key = Assert.Single(traitTest.Traits.Keys); Assert.Equal("Name!", key); string value = Assert.Single(traitTest.Traits[key]); Assert.Equal("Value!", value); ITestCase skipped = Assert.Single(testCases, tc => tc.DisplayName == "Namespace1.Class1.Skipped"); Assert.Equal("Skipping", skipped.SkipReason); Assert.Single(testCases, tc => tc.DisplayName == "Custom Test Name"); Assert.Single(testCases, tc => tc.DisplayName == "Namespace2.OuterClass+Class2.TestMethod"); } }
public TestCaseFinished(ITestCase testCase, decimal executionTime, int testsRun, int testsFailed, int testsSkipped) : base(testCase) { ExecutionTime = executionTime; TestsRun = testsRun; TestsFailed = testsFailed; TestsSkipped = testsSkipped; }
private ITestResult MakeFakeTestResult(ITestCase testCase) { var testResult = Substitute.For <ITestResult>(); testResult.TestCase.Returns(testCase); return(testResult); }
public static long GetTestOrder(ITestCase tc) { var tm = tc.TestMethod.Method; var toa = tm.GetCustomAttributes(typeof(TestOrderAttribute)).FirstOrDefault(); return(toa?.GetNamedArgument <int>(nameof(TestOrderAttribute.Order)) ?? int.MaxValue); }
/// <summary> /// Initializes a new instance of the <see cref="TestCaseCleanupFailure"/> class. /// </summary> public TestCaseCleanupFailure(ITestCase testCase, string[] exceptionTypes, string[] messages, string[] stackTraces, int[] exceptionParentIndices) : base(testCase) { StackTraces = stackTraces; Messages = messages; ExceptionTypes = exceptionTypes; ExceptionParentIndices = exceptionParentIndices; }
public static ExpectedExceptionTestCase ExpectedException(ITestCase testCase, Type exceptionType) { if (testCase == null) throw new ArgumentNullException("testCase"); if (exceptionType == null) throw new ArgumentNullException("exceptionType"); return new ExpectedExceptionTestCase(testCase, exceptionType); }
public bool Filter(IFixture fixture, ITestCase testCase) { XmlTestCase xtestCase = this.Searcher.GetTestCase(fixture.Name, testCase.Name); if (xtestCase == null) return false; else return xtestCase.State == TestState.Failure; }
/// <summary> /// Initializes a new instance of the <see cref="TestCaseFinished"/> class. /// </summary> public TestCaseFinished(ITestCase testCase, decimal executionTime, int testsRun, int testsFailed, int testsSkipped) : base(testCase) { ExecutionTime = executionTime; TestsRun = testsRun; TestsFailed = testsFailed; TestsSkipped = testsSkipped; }
// Filter bool TestCaseFilter(ITestCase itc) { if (null == this.strTest) { return(true); } return(itc.DisplayName.ToLowerInvariant().Contains(this.strTest.ToLowerInvariant())); }
public void BeforeTestCase(ITestCase test) { this.currentTest = new XmlTestCase(String.Format("{0}t{1}", this.currentFixture.ID, this.currentFixture.TestCases.Count), test.Name); this.currentFixture.TestCases.Add(this.currentTest); }
public ITestCase GetInstance() { lock (locker) { instance = instance ?? CreateInstance(); return(instance); } }
bool FilterIncludedNames(ITestCase testCase) { // No names in the filter == everything is okay if (IncludedNames.Count == 0) return true; return IncludedNames.Contains(testCase.DisplayName); }
/// <summary> /// Initializes a new instance of the <see cref="TestCaseDecoratorBase"/> class. /// </summary> /// <param name="testCase">The test case.</param> protected TestCaseDecoratorBase(ITestCase testCase) { if (testCase == null) { throw new ArgumentNullException("testCase"); } this.testCase = testCase; }
public void GoTo_Rules(ITestCase testCase) { MainWin.ContentArea.Content = new RuleViewer(testCase, MainWin); CurrentScreen = CurrentScreenType.RulesScreen; OnPropertyChanged("CurrentScreen"); CurrentTestcase = testCase; OnPropertyChanged("CurrentTestcase"); }
/// <summary> /// Initializes a new instance of the <see cref="TestCleanupFailure"/> class. /// </summary> public TestCleanupFailure(ITestCase testCase, string displayName, string[] exceptionTypes, string[] messages, string[] stackTraces, int[] exceptionParentIndices) : base(testCase, displayName) { StackTraces = stackTraces; Messages = messages; ExceptionTypes = exceptionTypes; ExceptionParentIndices = exceptionParentIndices; }
#region Add/Remove Test cases /// <summary> /// Adds the test case to the suite /// </summary> /// <param name="testCase"><see cref="TestCase"/> instance to add.</param> /// <exception cref="InvalidOperationException"> /// The suite already contains a test case with the same name as <paramref name="testCase"/>. /// </exception> public void Add(ITestCase testCase) { if (testCase == null) throw new ArgumentNullException("testCase"); if (this.testCases.Contains(testCase.Name)) throw new InvalidOperationException("TestCase " + testCase.Name + " already in collection"); this.testCases.Add(testCase);
bool IsIncluded(ITestCase testCase) { foreach (XUnitFilter filter in filters) { List <string> values; if (filter == null) { continue; } if (filter.FilterType == XUnitFilterType.Trait) { if (testCase.Traits == null || testCase.Traits.Count == 0) { continue; } if (!testCase.Traits.TryGetValue(filter.TraitName, out values)) { continue; } if (values == null || values.Count == 0) { // We have no values and the filter doesn't specify one - that means we match on // the trait name only. if (String.IsNullOrEmpty(filter.TraitValue)) { return(!filter.Exclude); } continue; } if (values.Contains(filter.TraitValue, StringComparer.OrdinalIgnoreCase)) { return(!filter.Exclude); } continue; } if (filter.FilterType == XUnitFilterType.TypeName) { Log.Info(LogTag, $"IsIncluded: filter: '{filter.TestCaseName}', test case name: {testCase.DisplayName}"); if (string.Compare(testCase.DisplayName, filter.TestCaseName, StringComparison.OrdinalIgnoreCase) == 0 || (testCase.DisplayName.Length > filter.TestCaseName.Length && testCase.DisplayName.StartsWith(filter.TestCaseName) && testCase.DisplayName [filter.TestCaseName.Length] == '(')) { return(!filter.Exclude); } continue; } throw new InvalidOperationException($"Unsupported filter type {filter.FilterType}"); } return(true); }
public void Execute() { try { mCaseQueue = new ConcurrentQueue<ITestCase>(); Handler = Case.Handler; if (Handler == null) Handler = new TestProcessHandler(); Started = true; this.StatisticalInfo.Reset(); this.StatisticalInfo.Success.Result(); this.StatisticalInfo.Error.Result(); GetDelayTimes(); Type caseType = Case.GetType(); object config = null; System.Reflection.PropertyInfo property = caseType.GetProperty("Config", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); if (property != null) { if (property.PropertyType.IsEnum || property.PropertyType.IsValueType || property.PropertyType == typeof(string)) { Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(Config); config = jobj["Value"].ToObject(property.PropertyType); } else { config = Newtonsoft.Json.JsonConvert.DeserializeObject(Config, property.PropertyType); } } for (int i = 0; i < Users; i++) { ITestCase item = (ITestCase)Activator.CreateInstance(caseType); if (property != null) { property.SetValue(item, config); } try { item.Init(); } catch (Exception e_) { AddError(new Exception(string.Format("test case init error {0}", e_.Message))); return; } item.Error = OnError; item.Success = OnSuccess; mCaseQueue.Enqueue(item); } System.Threading.ThreadPool.QueueUserWorkItem(OnExecute); } catch (Exception e_) { AddError(e_); } }
/// <summary> /// Initializes a new instance of the <see cref="TestCleanupFailure"/> class. /// </summary> public TestCleanupFailure(ITestCase testCase, string displayName, Exception ex) : base(testCase, displayName) { var failureInfo = ExceptionUtility.ConvertExceptionToFailureInformation(ex); ExceptionTypes = failureInfo.ExceptionTypes; Messages = failureInfo.Messages; StackTraces = failureInfo.StackTraces; ExceptionParentIndices = failureInfo.ExceptionParentIndices; }
/// <summary> /// Filters the given method using the defined filter values. /// </summary> /// <param name="testCase">The test case to filter.</param> /// <returns>Returns <c>true</c> if the test case passed the filter; returns <c>false</c> otherwise.</returns> public bool Filter(ITestCase testCase) { if (!FilterIncludedTraits(testCase)) return false; if (!FilterExcludedTraits(testCase)) return false; return true; }
public abstract IResponseData Execute(string endpointAddress, string accessToken, long accessTokenTtl, ITestCase testCase, Dictionary <string, string> savedState, IResourceManager resourceManager, string userAgent, RSACryptoServiceProvider proofKeyProviderNew, RSACryptoServiceProvider proofKeyProviderOld);
private void LoadTestCase(FileSystemInfo info, ISuite parentSuite) { ITestCase testcase = parentSuite.CreateTestCase(info.Name); (testcase as IRedefineTestNodeProperties).FullFileName = info.FullName + "\\content.txt"; testcase.Load(this); testcase.IsRunnable = true; NotifyOnAfterCreateNode(testcase); }
public TestCaseWorker(ITestCase testCase, int index) { if (testCase == null) { throw new ArgumentNullException("testCase"); } this.testCase = testCase; this.index = index; }
public static ITestCase DecorateTest(ITestCase testCase, MethodInfo method) { ITestCase test = testCase; foreach (TestDecoratorAttributeBase attribute in method.GetCustomAttributes(typeof(TestDecoratorAttributeBase), true)) { test = attribute.Decorate(test); } return test; }
public bool IsImplemented(ITestCase test) { var isImplemented = false; var implementation = (ITmiTestImplementation)test.Implementation; if (implementation != null) { isImplemented = true; Console.WriteLine(test.Id + " is already implemented"); } return isImplemented; }
int Compare(ITestCase x, ITestCase y) { var xHash = x.UniqueID.GetHashCode(); var yHash = y.UniqueID.GetHashCode(); if (xHash == yHash) return 0; if (xHash < yHash) return -1; return 1; }
bool FilterIncludedNameSpaces(ITestCase testCase) { // No assemblies in the filter == everything is okay if (IncludedNameSpaces.Count == 0) return true; if (IncludedNameSpaces.Count != 0 && IncludedNameSpaces.Any(a => testCase.TestMethod.TestClass.Class.Name.StartsWith($"{a}.", StringComparison.Ordinal))) return true; return false; }
private void ExecuteStep(ITestCase tc, ITestStep step) { step.ActualResult = ""; if (step.Action.IsElementDependent) ExecuteElementDependentAction(tc, step); else TryExecuteNonElementDependentAction(tc, step); PrepareDefectIfAny(tc, step); }
/// <summary> /// Initializes a new <see cref="TestCaseViewModel"/>. /// </summary> /// <param name="testCase">The backing TFS test case</param> /// <param name="automationService">Enables modification of a test case's associated automation</param> public TestCaseViewModel(ITestCase testCase, ITestCaseAutomationService automationService) { _testCase = testCase; _automationService = automationService; RemoveAutomationCommand = Command.For(this) .DependsOn(p => p.CanRemoveAutomation) .Executes(RemoveAutomation); _testCase.PropertyChanged += testCase_PropertyChanged; }
/// <summary> /// Associates a test case with an automated test. /// </summary> public void AssociateWithAutomation(ITestCase testCase, ITestAutomation automation) { // Create the associated automation. var implementation = testCase.Project.CreateTmiTestImplementation( automation.Name, automation.TestType, automation.Storage, automation.Identifier); // Save the test. If you are doing this for lots of test, you can consider // bulk saving too (outside of this method) for performance reason. testCase.WorkItem.Open(); testCase.Implementation = implementation; testCase.Save(); }
/// <inheritdoc/> public ISourceInformation GetSourceInformation(ITestCase testCase) { var navData = session.GetNavigationData(testCase.TestMethod.TestClass.Class.Name, testCase.TestMethod.Method.Name); if (navData == null) return EmptySourceInformation; return new SourceInformation { FileName = navData.FileName, LineNumber = navData.LineNumber }; }
/// <summary> /// Initializes a new instance of the <see cref="TestFailed"/> class. /// </summary> public TestFailed(ITestCase testCase, string testDisplayName, decimal executionTime, string output, Exception ex) : base(testCase, testDisplayName, executionTime, output) { var failureInfo = ExceptionUtility.ConvertExceptionToFailureInformation(ex); ExceptionTypes = failureInfo.ExceptionTypes; Messages = failureInfo.Messages; StackTraces = failureInfo.StackTraces; ExceptionParentIndices = failureInfo.ExceptionParentIndices; }
/// <summary> /// Filters the given method using the defined filter values. /// </summary> /// <param name="testCase">The test case to filter.</param> /// <returns>Returns <c>true</c> if the test case passed the filter; returns <c>false</c> otherwise.</returns> public bool Filter(ITestCase testCase) { if (!FilterIncludedMethodsAndClasses(testCase)) return false; if (!FilterIncludedTraits(testCase)) return false; if (!FilterExcludedTraits(testCase)) return false; if (!FilterIncludedNameSpaces(testCase)) return false; return true; }