简体   繁体   English

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

[英]I want Canopy web testing results to show in VS 2013 test explorer… and I'm SO CLOSE

I'm trying to figure out how to get the test results for Canopy to show in the VS test explorer. 我正在试图弄清楚如何让Canopy的测试结果显示在VS测试资源管理器中。 I can get my tests to show up and it will run them but it always shows a pass. 我可以让我的测试出现,它会运行它们,但它总是显示通过。 It seems like the Run() function is "eating" the results so VS never sees a failure. 似乎Run()函数正在“吃掉”结果,所以VS永远不会看到失败。

I'm sure it is a conflict between how Canopy is nicely interpreting the exceptions it gets into test results because normally you'd want Run() to succeed regardless of the outcome and report its results using its own reports. 我确信Canopy如何很好地解释它进入测试结果的异常之间存在冲突,因为通常你希望Run()无论结果如何都能成功并使用自己的报告报告其结果。

Maybe I should be redirecting output and interpreting that in the MS testing code? 也许我应该重定向输出并在MS测试代码中解释它?

So here is how I have it set up right now... 所以这就是我现在设置的方式......

The Visual Studio Test Runner looks at this file for what it sees as tests, these call the canopy methods that do the real testing. 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() 
        ()

myTestModule looks like 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

I have it working now. 我现在有工作。 I put the below after the run() for each test. 我在每次测试的run()之后放下面的。

    Assert.IsTrue(canopy.runner.failedCount = 0,results.ToString())

so now my tests look something like: 所以现在我的测试看起来像:

    [<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())

Canopy and the UnitTesting infrastructure have some overlap in what they want to take care of. Canopy和UnitTesting基础设施在他们想要处理的事情上有一些重叠。 I want the UnitTesting infrasturcture to be the thing "reporting" the summary of all tests and details so I needed to find a way to "reset" the canopy portion so that I didn't have to track the last known state from canopy and then compare. 我希望UnitTesting基础设施能够“报告”所有测试和细节的摘要,因此我需要找到一种“重置”冠层部分的方法,这样我就不必从冠层跟踪最后的已知状态然后相比。 So for this to work your canopy suite can only have one test but we want to have as many as we want at the UnitTesting level. 因此,为了实现这一目标,您的canopy套件只能进行一次测试,但我们希望在UnitTesting级别拥有尽可能多的测试。 To adjust for that we do the below in the []. 为了调整,我们在[]中进行以下操作。

    runner.suites <- [new suite()]
    runner.failedCount <- 0
    runner.passedCount <- 0

It might make sense to have something within canopy that could be called or configured when the user wants to use a different unit testing infrastructure around canopy. 当用户想要在树冠周围使用不同的单元测试基础设施时,在树冠内部可以调用或配置的东西可能是有意义的。

Additionally I wanted the output that includes the error information to appear as it normally does when a test fails so I capture the console.out in a stringBuilder and clear that in []. 另外,我希望包含错误信息的输出在测试失败时正常显示,因此我在stringBuilder中捕获console.out并在[]中清除它。 I set it up in by including the below [] where common.results is the StringBuilder I then use in the asserts. 我通过包含下面的[]来设置它,其中common.results是我在然后在断言中使用的StringBuilder。

    System.Console.SetOut(new System.IO.StringWriter(common.results))

创建一个可变类型以传递给'myTestModule.all'调用,该调用可以在失败时相应地更新,并在'run()'完成后断言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM