我希望Canopy网络测试结果能够在VS 2013测试资源管理器中显示...而且我很接近

Bet*_*zel 8 f# test-explorer visual-studio-2013 canopy-web-testing

我正在试图弄清楚如何让Canopy的测试结果显示在VS测试资源管理器中.我可以让我的测试出现,它会运行它们,但它总是显示通过.似乎Run()函数正在"吃掉"结果,所以VS永远不会看到失败.

我确信Canopy如何很好地解释它进入测试结果的异常之间存在冲突,因为通常你希望Run()无论结果如何都能成功并使用自己的报告报告其结果.

也许我应该重定向输出并在MS测试代码中解释它?

所以这就是我现在设置的方式......

Visual Studio Test Runner查看此文件以查看其所见的测试,这些调用称为执行实际测试的canopy方法.

open canopy
open runner
open System
open Microsoft.VisualStudio.TestTools.UnitTesting

[<TestClass>]
type testrun() = 

    // Look in the output directory for the web drivers    
    [<ClassInitialize>]
    static member public setup(context : TestContext) =
        // Look in the output directory for the web drivers    
        canopy.configuration.ieDir <- "."
        canopy.configuration.chromeDir <- "."

        // start an instance of the browser
        start ie
        ()

    [<TestMethod>]
    member x.LocationNoteTest() =
        let myTestModule = new myTestModule()
        myTestModule.all()
        run()


    [<ClassCleanup>]
    static member public cleanUpAfterTesting() =
        quit() 
        ()
Run Code Online (Sandbox Code Playgroud)

myTestModule看起来像

open canopy
open runner
open System

type myTestModule() =

    // some helper methods

    member x.basicCreate() =
        context "The meat of my tests"

        "Test1" &&& fun _ ->
            // some canopy test statements like...
            url "http://theURL.com/"

            "#title" == "The title of my page"

            //Does the text of the button match expectations?
            "#addLocation" == "LOCATION"

            // add a location note
            click ".btn-Location"

     member x.all() = 
        x.basicCreate()
        // I could add additional tests here or I could decide to call them individually
Run Code Online (Sandbox Code Playgroud)

Bet*_*zel 6

我现在有工作.我在每次测试的run()之后放下面的.

    Assert.IsTrue(canopy.runner.failedCount = 0,results.ToString())
Run Code Online (Sandbox Code Playgroud)

所以现在我的测试看起来像:

    [<TestMethod>]
    member x.LocationNoteTest() =
            let locationTests = new LocationNote()

            // Add the test to the canopy suite
            // Note, this just defines the tests to run, the canopy portion
            // of the tests do not actually execute until run is called.
            locationTests.all()

            // Tell canopy to run all the tests in the suites.
            run()

            Assert.IsTrue(canopy.runner.failedCount = 0,results.ToString())
Run Code Online (Sandbox Code Playgroud)

Canopy和UnitTesting基础设施在他们想要处理的事情上有一些重叠.我希望UnitTesting基础设施能够"报告"所有测试和细节的摘要,因此我需要找到一种"重置"冠层部分的方法,这样我就不必从冠层跟踪最后的已知状态然后相比.因此,为了实现这一目标,您的canopy套件只能进行一次测试,但我们希望在UnitTesting级别拥有尽可能多的测试.为了调整,我们在[]中进行以下操作.

    runner.suites <- [new suite()]
    runner.failedCount <- 0
    runner.passedCount <- 0
Run Code Online (Sandbox Code Playgroud)

当用户想要在树冠周围使用不同的单元测试基础设施时,在树冠内部可以调用或配置的东西可能是有意义的.

另外,我希望包含错误信息的输出在测试失败时正常显示,因此我在stringBuilder中捕获console.out并在[]中清除它.我通过包含下面的[]来设置它,其中common.results是我在然后在断言中使用的StringBuilder.

    System.Console.SetOut(new System.IO.StringWriter(common.results))
Run Code Online (Sandbox Code Playgroud)