【问题标题】:BDD of UI Components with WatiN and SpecFlow使用 WatiN 和 SpecFlow 的 UI 组件的 BDD
【发布时间】:2011-06-20 02:08:51
【问题描述】:

我的问题集中在我的设置当前是否遵循有关 BDD 和 UI 验收测试的最佳实践方法。我正在使用带有 SpecFlow 的 WatiN 来构建我的 UI 验收测试,并将我的应用程序部署到 AppHarbor(一个云平台即 .Net 应用程序的服务)。 AppHarbor 在部署时运行您的单元/集成测试,并且只有在您的测试通过时才会推送您的站点。所以我首先编写了一个基本的失败测试,​​如下所示:

Scenario: Navigation to homepage
          When I navigate to /
          Then I should be on the application homepage

与此测试相关的步骤使用 WatiN 打开浏览器并验证视图的标题属性是否设置为“欢迎”。我正在检查环境以确定使用 WatiN 浏览器测试的 URL。例如,如果在开发中导航到“http://localhost:49641/”作为主页。否则,导航到“http://myappharborapp.com/”。

我的问题是,如果您是第一次部署此应用程序,页面或视图实际上不存在,因此测试失败(因为该站点尚未上线)。例如,如果我稍后添加“关于”页面视图并首先编写失败的测试,这也会失败。当我推送更新时,测试将失败,因为“关于”页面尚不存在。

那么我的问题是:关于您应该如何设置 UI 测试,我是否没有遵循最佳实践?应该如何设置这些测试以便它们在任何环境中通过?

非常感谢任何见解!

【问题讨论】:

    标签: watin bdd specflow


    【解决方案1】:

    在“传统的”watin 测试中,我使用自定义属性来指定应用程序的版本和运行环境,然后如果缺少条件,则跳过测试。

    (代码在parkcalc示例>观察者>环境监视器中的http://testingstax.codeplex.com开源)

        internal static void CheckSetEnvironment()
        {
            Object[] attributes = Utility.GetCallerAttributes(typeof(ExecutionEnvironment), 3);
    
            CheckEnvironment(attributes);
        }
    
        private static void CheckEnvironment(Object[] attributes)
        {
            TestEnvironment = GetCurrentEnvironment();
    
            if (attributes.Length > 0 && !attributes.Contains(new ExecutionEnvironment(TestEnvironment)))
            {
                Assert.Inconclusive("This test is not designed to be executed in the '" + TestEnvironment.ToString() + "' environment.");   
            }
        }
    
        private static EnvironmentType GetCurrentEnvironment()
        {
            string currentEnvironment = ConfigurationManager.AppSettings["Environment"].ToLower(CultureInfo.CurrentCulture);
            EnvironmentType Environment = new EnvironmentType();
    
            try
            {
                Environment = (EnvironmentType)Enum.Parse(typeof(EnvironmentType), currentEnvironment, true);
            }
            catch (System.ArgumentException)
            {
                Assert.Fail(" The current environment setting in 'Environment' in the app.config is invalid.");
            }
            return Environment;
        }
    

    然后诀窍是映射一个规范流操作以忽略测试

    “鉴于测试没有在生产中运行”或类似的东西

    【讨论】:

    • 感谢布鲁斯的回复。我会试一试这个实现,看起来它应该适合我的目的。
    猜你喜欢
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2011-07-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多