jeudi 31 mars 2016

How do I find any attributes in calling code?

I have a test setup where I decorate tests with attributes telling if a test can run under some circumstances. Deep down in my code I want to check if the test method has a certain attribute. Can this be accomplished?

My tests look like this:

[TestClass, ParallelSeleniumTest, ExcludeFromCodeCoverage]
public class ExportIncident : ViewTest
{
    [TestMethod, TestCategory("ExcludeFromBuildServer"), SupportedBrowsers(Browser.FireFox)]
    public void Export()
    {
        ...
    }
}

And deep down where I want to assert the SupportedBrowserAttributevalue my code looks like this:

internal static RemoteWebDriver CreateDriver()
{
    RemoteWebDriver driver;

    // ReSharper disable HeuristicUnreachableCode
    switch (TestRunSettings.BrowserToUse)
    {
        case Browser.Firefox:
            driver = CreateFirefoxDriver();
            break;
        case Browser.Chrome:
            driver = CreateChromeDriver();
            break;
        case Browser.InternetExplorer:
            driver = CreateInternetExplorerDriver();
            break;
        default:
            throw new ArgumentOutOfRangeException();
    }

    InitDriver(driver);

    return driver;
}

BrowserToUse is a constant in a file.





Aucun commentaire:

Enregistrer un commentaire