In my Powershell script (PSAKE), I have the ability to specify the Namespace/Fixture to run when I execute the NUnit test runner.
task UnitTest -Depends Compile -Description "Runs only Unit Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Unit" $buildArtifactsDir
}
task IntegrationTest -Depends Compile -Description "Runs only Integration Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Integration" $buildArtifactsDir
}
task FunctionalTest -Depends Compile -Description "Runs only Functional Tests" {
Invoke-Nunit "$buildOutputDir\$testAssembly.dll" "$testAssembly.Functional" $buildArtifactsDir
}
This allows me to have three outputs
Unit-TestResults.xml
Integration-TestResults.xml
Functional-TestResults.xml
I'm in the process of switching over to FAKE because it's just so much cleaner to maintain, however I can't figure out how to specify the Fixture for my test.
IE: right now I have
// Run Tests
Target "Tests" (fun _ ->
testDlls
|> NUnit (fun p ->
{p with
DisableShadowCopy = true;
OutputFile = artifactDir + "/TestResults.xml"
})
)
But this runs ALL the tests and drops it into a single output. I'd really like to specify the Fixture, and be able to split it all up. Is there a way to do this?
Newest version of FAKE added support for Fixture parameter. You should be able to do:
Target "Tests" (fun _ ->
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Unit"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Unit-TestResults.xml"
})
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Integration"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Integration-TestResults.xml"
})
testDlls
|> NUnit (fun p ->
{p with
Fixture ="Namespace.Functional"
DisableShadowCopy = true;
OutputFile = artifactDir + "/Functional-TestResults.xml"
})
)
Related
I'm trying to write some logs in an Expecto test, however I can't figure out how to get anything to be logged. Is there a very simple example of this somewhere? Currently I have:
module Test
open Expecto
open Expecto.Logging
open Expecto.Logging.Message
open Hopac
open Logary.Configuration
open Logary.Adapters.Facade
open Logary.Targets
[<Tests>]
let tests =
test "A simple test" {
let logger = Log.create "asdf.qwer"
let one = 1
ignore (logger.logWithAck Debug (eventX "asdf"))
Expect.equal one 1 "Should equals 1"
}
[<EntryPoint>]
let main argv =
let logary =
Config.create "MyProject.Tests" "localhost"
|> Config.targets [ LiterateConsole.create LiterateConsole.empty "console" ]
|> Config.processing (Events.events |> Events.sink ["console";])
|> Config.build
|> run
LogaryFacadeAdapter.initialise<Expecto.Logging.Logger> logary
// Invoke Expecto:
runTestsInAssemblyWithCLIArgs [] argv
I am using DotCoverNUnit in FAKE for code coverage .
It is giving some error
`Starting Target: TestCoverage (==> BuildUnitTest)
./Buildtools/dotCover/dotCover.exe "cover" "/TargetExecutable=./Libs/NUnit.Runners.2.6.3/tools/nunit-console.exe" "/TargetArguments="-nologo" "-labels" "D:\Project\build\project.UnitTest.dll" "-xml:D:\Project\TestResult.xml"" "/Output=./test/NUnitDotCover.xml"
./Buildtools/dotCover/dotCover.exe "cover" "/TargetExecutable=./Libs/NUnit.Runners.2.6.3/tools/nunit-console.exe" "/TargetArguments="-nologo" "-labels" "D:\Project\build\Project.UnitTest.dll" "-xml:D:\Project\TestResult.xml"" "/Output=./test/NUnitDotCover.xml"
JetBrains dotCover Console Runner v2.6.608.684. Copyright (c) 2009–2017 JetBrains s.r.o. All rights reserved.
**Command 'cover' doesn't support 4 unnamed arguments**
Type 'dotCover help' for usage.
Running build failed.
Error:
System.Exception: Error running ./Buildtools/dotCover/dotCover.exe with exitcode -1
at Fake.DotCover.buildParamsAndExecute#124-6.Invoke(String message)
at Fake.DotCover.buildParamsAndExecute[a](a parameters, FSharpFunc2 buildArguments,String toolPath, String workingDir, Boolean failBuild)
at Fake.DotCover.DotCoverNUnit(FSharpFunc 2 setDotCoverParams, FSharpFunc2 setNUnitParams, IEnumerable 1 assemblies)
at FSI_0005.Build.clo#98-8.Invoke(Unit _arg6) in D:\ICIS API develop\icis-api\build.fsx:line 99`
I am not able to figure out the problem out there in this code , I was able to run this code earlier but right now it is not wroking .
Here is the code that I am using for DotCover :
Target "TestCoverage" (fun _ ->
!! (buildDir ## "/Project.UnitTest.dll")
|> DotCoverNUnit
(fun p -> { p with TargetExecutable ="nunit-console.exe"
Output ="NUnitDotCover.xml"
ToolPath = "dotCover.exe"
ErrorLevel = DontFailBuild
Filters = filters })
(fun nunitOptions ->
{ nunitOptions with DisableShadowCopy = true })
tracefn "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='%s']" (testDir ## "NUnitDotCover.xml")
)
I am trying to use dotCover in FAKE .I am getting an error i.e. DotCoverNUnit is not defined .I think this is the problem with the package .
Here is my Code for DotCover in FAKE :
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit (fun p ->
{ p with
Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
)
Please tell me how to install DotCover in Fake or how to use this . This would be very helpful .
The Fake.DotCover module is not auto-opened, so its functions aren't available until you do open Fake.DotCover near the top of your script.
Unfortunately, the FAKE API documentation currently isn't very good at telling you which modules are auto-opened and which ones need open (modulename) in order to expose their functions.
Update: The way you should be calling DotCoverNUnit is as follows:
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit
(fun p -> { p with Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters })
(fun nunitOptions -> nunitOptions)
)
Or, if you want to change some of the NUnit options:
let filters = ""
Target "TestCoverage" (fun _ ->
!! ("D:/Test/Project/Project1/UnitTests/UnitTest.dll")
|> DotCoverNUnit
(fun dotCoverOptions ->
{ dotCoverOptions with Output = testDir ## "NUnitDotCover.snapshot"
Filters = filters })
(fun nunitOptions ->
{ nunitOptions with ExcludeCategory = "Manual,LongRunning"
DisableShadowCopy = true })
)
See http://fsharp.github.io/FAKE/apidocs/fake-nunitcommon-nunitparams.html for the complete list of what NUnit options are available from inside FAKE.
I have a FAKE build script that contains a DotCover coverage step using using the DotCoverNUnit3 extension:
let filters = ""
!! (buildDir ## "/*.UnitTests.dll")
|> DotCoverNUnit3 (fun p ->
{ p with
Output = artifactsDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
The snapshot generates correctly, but the coverage overview doesn't appear in the TeamCity build.
I then tried calling DotCoverReport after building the snapshot:
DotCoverReport (fun p ->
{ p with
Source = artifactsDir ## "NUnitDotCover.snapshot"
Output = artifactsDir ## "NUnitDotCover.xml"
ReportType = DotCoverReportType.Xml }) true
This generates the expected XML report, but again, the coverage overview doesn't appear in the build overview page.
As a side note - I'm not sure what the boolean parameter on the end of the DotCoverReport method is, can't find a reference to it on the FAKE docs. I tried switching the value, but it didn't make a difference.
Does anyone know how I can get TeamCity to pickup the DotCover report?
Found a solution.
After drilling down through many layers of TeamCity documentation, I found this page: https://confluence.jetbrains.com/display/TCD9/Manually+Configuring+Reporting+Coverage
Which describes using service messages to point TeamCity in the direction of the snapshot.
So, in the end I didn't need the DotCoverReport, just the snapshot:
For dotCover you should send paths to the snapshot file that is generated by the dotCover.exe cover command.
This is my resulting Target:
let artifactsDir = environVarOrDefault "ARTIFACT_DIR" (currentDirectory ## "artifacts")
let nunitOptions nUnit3Defaults =
{ NUnit3Defaults with
TimeOut = TimeSpan.MaxValue
WorkingDir = artifactsDir }
Target "TestCoverage" (fun _ ->
let filters = ""
!! (buildDir ## "/*.UnitTests.dll")
|> DotCoverNUnit3 (fun p ->
{ p with
Output = artifactsDir ## "NUnitDotCover.snapshot"
Filters = filters }) nunitOptions
tracefn "##teamcity[importData type='dotNetCoverage' tool='dotcover' path='%s']" (artifactsDir ## "NUnitDotCover.snapshot")
)
Having
type Category(name : string, categoryType : CategoryType) =
do
if (name.Length = 0) then
invalidArg "name" "name is empty"
i'm trying to test this exception using FsUnit + xUnit:
[<Fact>]
let ``name should not be empty``() =
(fun () -> Category(String.Empty, CategoryType.Terminal)) |> should throw typeof<ArgumentException>
but when it runs I see XUnit.MatchException.
What i'm doing wrong?
Test source code
Category type source code
While I'm not an FsUnit expert, I think the MatchException type is expected, because FsUnit uses custom matchers, and the match doesn't succeed.
However, the test, as written, seems to be incorrect, because
(fun () -> Category(String.Empty, CategoryType.Terminal)
is a function with the signature unit -> Category, but you don't really care about the returned Category.
Instead, you can write it as
[<Fact>]
let ``name should not be empty``() =
(fun () -> Category(String.Empty, CategoryType.Terminal) |> ignore)
|> should throw typeof<ArgumentException>
Notice the added ignore keyword, which ignores the Category return value. This test passes, and fails if you remove the Guard Clause.