From a18b1375f082399652f67ab8de41a75f69559cab Mon Sep 17 00:00:00 2001 From: Limo Wan Kenobi Date: Fri, 16 Oct 2015 16:42:36 +0200 Subject: [PATCH 1/4] failing test --- tests/basictests/Program.fs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index b4fbeaa7..70abac8e 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -643,7 +643,7 @@ context "Resize tests" start chrome url "http://resizemybrowser.com/" resize screenSizes.iPhone4 - "#cWidth" == "320" + "#cWidth" == "357" "#cHeight" == "480" quit browser switchTo mainBrowser @@ -663,7 +663,7 @@ context "Resize tests" url "http://resizemybrowser.com/" resize screenSizes.iPhone4 rotate() - "#cHeight" == "320" + "#cHeight" == "357" "#cWidth" == "480" quit browser switchTo mainBrowser @@ -699,6 +699,26 @@ context "todo tests" "write a test that tests the whole internet!" &&& todo +let createTest n = + let testName = sprintf "Testing welcome %i" n + + let testBody _ = + url testpage + "#welcome" == "Welcome" + + testName &&& todo + + +let createTestSuite contextName n = + context contextName + + [1..n] + |> Seq.iter createTest + +start chrome + +createTestSuite "Add test performance" 100000 + run () switchTo mainBrowser From 599d6138cf06b4e3ffa9de05bf1628388e039dd9 Mon Sep 17 00:00:00 2001 From: Limo Wan Kenobi Date: Sat, 17 Oct 2015 21:45:59 +0200 Subject: [PATCH 2/4] Fixed failed tests. Adding 1000 tests is enough. --- tests/basictests/Program.fs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index 70abac8e..bb07a766 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -643,7 +643,7 @@ context "Resize tests" start chrome url "http://resizemybrowser.com/" resize screenSizes.iPhone4 - "#cWidth" == "357" + "#cWidth" == "320" "#cHeight" == "480" quit browser switchTo mainBrowser @@ -663,7 +663,7 @@ context "Resize tests" url "http://resizemybrowser.com/" resize screenSizes.iPhone4 rotate() - "#cHeight" == "357" + "#cHeight" == "320" "#cWidth" == "480" quit browser switchTo mainBrowser @@ -717,7 +717,7 @@ let createTestSuite contextName n = start chrome -createTestSuite "Add test performance" 100000 +createTestSuite "Add test performance" 1000 run () From f6eac290592297ecca684531c70e2903c28930b4 Mon Sep 17 00:00:00 2001 From: Limo Wan Kenobi Date: Sat, 17 Oct 2015 22:01:19 +0200 Subject: [PATCH 3/4] Add elements to lists instead of concatenating two lists. --- src/canopy/runner.fs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/canopy/runner.fs b/src/canopy/runner.fs index 4698bd04..9f72fe8d 100644 --- a/src/canopy/runner.fs +++ b/src/canopy/runner.fs @@ -7,10 +7,9 @@ open reporters open types open OpenQA.Selenium -let rec private last = function - | hd :: [] -> hd - | hd :: tl -> last tl - | _ -> failwith "Empty list." +let private last = function + | hd :: tl -> hd + | [] -> failwith "Empty list." let mutable suites = [new suite()] let mutable todo = fun () -> () @@ -26,30 +25,30 @@ let context c = else let s = new suite() s.Context <- c - suites <- suites @ [s] + suites <- s::suites let private incrementLastTestSuite () = let lastSuite = last suites lastSuite.TotalTestsCount <- lastSuite.TotalTestsCount + 1 lastSuite let ( &&& ) description f = let lastSuite = incrementLastTestSuite() - lastSuite.Tests <- lastSuite.Tests @ [Test(description, f, lastSuite.TotalTestsCount)] + lastSuite.Tests <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Tests let test f = null &&& f let ntest description f = description &&& f let ( &&&& ) description f = let lastSuite = incrementLastTestSuite() - lastSuite.Wips <- lastSuite.Wips @ [Test(description, f, lastSuite.TotalTestsCount)] + lastSuite.Wips <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Wips let wip f = null &&&& f let many count f = let lastSuite = incrementLastTestSuite() - [1 .. count] |> List.iter (fun _ -> lastSuite.Manys <- lastSuite.Manys @ [Test(null, f, lastSuite.TotalTestsCount)]) + [1 .. count] |> List.iter (fun _ -> lastSuite.Manys <- Test(null, f, lastSuite.TotalTestsCount)::lastSuite.Manys) let ( &&! ) description f = let lastSuite = incrementLastTestSuite() - lastSuite.Tests <- lastSuite.Tests @ [Test(description, skipped, lastSuite.TotalTestsCount)] + lastSuite.Tests <- Test(description, skipped, lastSuite.TotalTestsCount)::lastSuite.Tests let xtest f = null &&! f let ( &&&&& ) description f = let lastSuite = incrementLastTestSuite() - lastSuite.Always <- lastSuite.Always @ [Test(description, f, lastSuite.TotalTestsCount)] + lastSuite.Always <- Test(description, f, lastSuite.TotalTestsCount)::lastSuite.Always let mutable passedCount = 0 let mutable skippedCount = 0 let mutable failedCount = 0 @@ -88,8 +87,12 @@ let failSuite (ex: Exception) (suite : suite) = let reportFailedTest (ex: Exception) (test : Test) = reporter.testStart test.Id fail ex test.Id <| safelyGetUrl() - reporter.testEnd test.Id - suite.Tests |> List.iter (fun test -> reportFailedTest ex test) + reporter.testEnd test.Id + + // tests are in reverse order and have to be reversed first + do suite.Tests + |> List.rev + |> List.iter (fun test -> reportFailedTest ex test) let run () = reporter.suiteBegin() @@ -120,6 +123,9 @@ let run () = reporter.testEnd test.Id failureMessage <- null + + // suites list is in reverse order and have to be reversed before running the tests + suites <- List.rev suites //run all the suites if runFailedContextsFirst = true then @@ -149,13 +155,13 @@ let run () = tests |> List.iter (fun w -> runtest s w) wipTest <- false else if s.Manys.IsEmpty = false then - s.Manys |> List.iter (fun m -> runtest s m) + s.Manys |> List.rev |> List.iter (fun m -> runtest s m) else let tests = s.Tests @ s.Always |> List.sortBy (fun t -> t.Number) tests |> List.iter (fun t -> runtest s t) s.Lastly () - if contextFailed = true then failedContexts <- failedContexts @ [s.Context] + if contextFailed = true then failedContexts <- s.Context::failedContexts if s.Context <> null then reporter.contextEnd s.Context ) @@ -166,7 +172,8 @@ let run () = reporter.suiteEnd() let runFor browsers = - let currentSuites = suites + // suites are in reverse order and have to be reversed before running the tests + let currentSuites = suites |> List.rev suites <- [new suite()] match box browsers with | :? (types.BrowserStartMode list) as browsers -> From b9029134a64fc202c78ba2cfd19a94e58ffacaca Mon Sep 17 00:00:00 2001 From: Edgar Hernandez Date: Sat, 17 Oct 2015 22:28:18 +0200 Subject: [PATCH 4/4] "Add tests performance" test improvements - Removed the unused testBody - Changed message - Changed variable name --- tests/basictests/Program.fs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/tests/basictests/Program.fs b/tests/basictests/Program.fs index bb07a766..98d17fbe 100644 --- a/tests/basictests/Program.fs +++ b/tests/basictests/Program.fs @@ -699,21 +699,14 @@ context "todo tests" "write a test that tests the whole internet!" &&& todo -let createTest n = - let testName = sprintf "Testing welcome %i" n - - let testBody _ = - url testpage - "#welcome" == "Welcome" - +let createTest k = + let testName = sprintf "Testing addition performance %i" k testName &&& todo - let createTestSuite contextName n = context contextName - [1..n] - |> Seq.iter createTest + [1..n] |> Seq.iter createTest start chrome @@ -726,4 +719,4 @@ coverage testpage coverage() coverage "http://scrumy.com/silenter39delayed" -quit() \ No newline at end of file +quit()