华廷:如何使用自动化测试运行的结果,因为我无法得到报告的试运行结果的方式 [英] WatiN:How to use the automated test run result as I am unable to get the way of Reporting the result of the test run

查看:202
本文介绍了华廷:如何使用自动化测试运行的结果,因为我无法得到报告的试运行结果的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经与自动化一华廷模块现在我要显示的测试结果为PASS / FAIL状态等(报告),是否有任何华廷功能,做我需要采取行动。

I have automated a module with WATIN and now I want the test result to be displayed as PASS/FAIL status etc(REPORTING), Is there any functionality in Watin to do my required action.

就像我有一个code像

Like I have a code like

    public static void TestSelectPatientLink()

    {

        try

        {

            Link lnkSelectPatientb = ie.Link(Find.ByTitle("Search patient"));
            lnkSelectPatientb.Blur();
            lnkSelectPatientb.ClickNoWait();

        }

        catch (Exception ex)

        {

            Console.WriteLine(ex.ToString());

        }

    }

如何获得的报告时,该code在VS 2010中运行发生了什么事,难道失败或传球,如果失败,错误等,如何报道这些事情。

How to get the report as what happened when this code runs in VS 2010, Is it failing or passing, If it fails, the error etc, How to report these things.

**仅供参考,我使用NUnit与华廷

**FYI I am using Nunit with WatiN

推荐答案

没有,没有内置任何华廷功能来支持这一点,但GarethStephenson的职位是正确的。你可以写一个NUnit的测试会给你一个合格/不合格。

No, there isn't any functionality built into WatiN to support this, but GarethStephenson's post was correct. You can write an NUnit test that will give you a pass/fail.

首先,IE浏览器与NUnit的工作,你需要将以下添加到您的app.config

First of all, for IE to work with NUnit you need to add the following to your app.config

<configSections>
  <sectionGroup name="NUnit">
    <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
  </sectionGroup>
</configSections>

<NUnit>
  <TestRunner>
    <!-- Valid values are STA,MTA. Others ignored. -->
    <add key="ApartmentState" value="STA" />
  </TestRunner>
</NUnit>

下面是一个例子测试。它加载了谷歌的主页上,抓住一些元素,并声称他们的存在: -

Here's an example test. It loads up the google home page, grabs some elements and asserts they exist: -

using WatiN.Core;
using NUnit.Framework;

namespace ConsoleApplication1
{
    [TestFixture]
    public class AutomatedTests
    {
        [Test]
        public void DoGoogleTest()
        {
            using (IE browser = new IE())
            {
                browser.GoTo("www.google.co.uk");

                Div logoDiv = browser.Div("hplogo");
                Assert.IsTrue(logoDiv.Exists, "Logo div does not exist");

                TextField searchText = browser.TextField("lst-ib");
                Assert.IsTrue(searchText.Exists, "Search text field does not exist");

                Button searchBtn = browser.Button(Find.ByName("btnK"));
                Assert.IsTrue(searchBtn.Exists, "Search button does not exist");

                Button nonExistantButton = browser.Button("garbagegarbagegarbage");
                // This will cause the test to fail because the link doesn't (shouldn't!) exist.
                // Comment it out and the test should pass
                Assert.IsTrue(nonExistantButton.Exists, "Non-existant button does not exist");
            }
        }
    }
}

不幸的是,NUnit的不自动与视觉工作室测试视图/测试列表窗口整合。您可以选择: -

Unfortunately, NUnit doesn't automatically integrate with Visual Studios Test View/Test List windows. Your options are: -


  • 视觉NUnit的

  • 加利奥(这将整合,也是很好的报告)

  • 外部运行测试(从而可以通过VS 完成)

  • Install Visual NUnit
  • Install Gallio (which will integrate and is good for reporting)
  • Run your tests externally (which can be done through VS)

以上code给我的结果: -

The above code gives me the result: -

ConsoleApplication1.AutomatedTests.DoGoogleTest:
  Non-existant button does not exist
  Expected: True
  But was:  False

如果您注释掉最后一行你没有错误报告。

If you comment out the last line you get no errors reported.

如果您需要任何更多的信息,然后让我知道。 HTH!

If you need any more info then let me know. HTH!

修改添加链接视觉NUnit的扩展VS2010

EDIT Added link for Visual NUnit extension for VS2010

这篇关于华廷:如何使用自动化测试运行的结果,因为我无法得到报告的试运行结果的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆