Skip to content

Instantly share code, notes, and snippets.

@teamaton
Created November 25, 2013 10:47
Show Gist options
  • Save teamaton/7639546 to your computer and use it in GitHub Desktop.
Save teamaton/7639546 to your computer and use it in GitHub Desktop.
Extract full test method name from currently running SpecFlow scenario
private static void SaveTestNameToFailedTestsFile() {
var scenarioDesc = ScenarioContext.Current.ScenarioInfo.Title;
var methodInfos = typeof (InfrastructureSteps).Assembly.GetTypes()
.SelectMany(
type => type.GetMethods()
.Where(m => m.GetCustomAttributes(typeof (DescriptionAttribute), false)
.Any(attr => ((DescriptionAttribute) attr).Description == scenarioDesc)));
foreach (var methodInfo in methodInfos) {
var fullMethodName = methodInfo.ReflectedType.FullName + "." + methodInfo.Name;
Log.Info("Saving current test method name: {0}", fullMethodName);
File.AppendAllText(_failedTestsFile, fullMethodName + Environment.NewLine);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment