Search code examples
vb.netvisual-studioseleniumiis-expressopencover

Code Coverage of a Selenium Test


I have installed OpenCover through nuget.

This is the line I'm running from my Command Prompt

C:\myapp\Main\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"C:\Program Files (x86)\NUnit 2.6.4\bin\nunit-console.exe" -register:user -targetargs:"C:\myapp\Main\myapp.SeleniumTests\bin\Debug\myapp.seleniumTests.dll /result=c:\TestRunner\SeleniumResults.xml /include:Single"

I can see that the test runs because FireFox opens up and it goes through all the necesary steps. but once its done I get "Visisted Classes 0 of 309"

I have tried adding

-searchdirs:"C:\myApp\Main\MainWebProject\bin"

but still it comes back with no coverage.

What am I missing?


Solution

  • Ok I was able to make it run. It's important that Visual Studio is closed, if not it will have trouble registering the site from iis express

    first in the console I go to

    cd c:\MyApp\Main\MainWebProject\Bin
    

    the script came out to:

    C:\MyApp\Main\packages\OpenCover.4.6.519\tools\OpenCover.Console.exe -target:"C:\Users\Me\Desktop\TestRunnerWithServer.bat" -register:user -searchdirs:"C:\MyApp\Main\MainWebProject\bin"
    

    the file "TestRunnerWithServer.bat" has the following steps

    del "C:\TestRunner\TestResults.xml"
    del "c:\TestRunner\SeleniumResults.xml"
    
    call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
    
    rem go to the folder of the project with the unit tests
    CD C:\MyApp\Main\MyTestsProject\bin\Debug
    
    rem Run Unit Tests
    MStest /testcontainer:MyTestsProject.dll /resultsfile:C:\TestRunner\TestResults.xml
    
    rem now start IIS Express in a different window
    cd C:\Program Files (x86)\IIS Express\
    start iisexpress.exe /site:MainWebProject /config:C:\MyApp\Main\.vs\config\applicationhost.config
    
    CD C:\Program Files (x86)\NUnit 2.6.4\bin
    
    rem Run Selenium Tests
    nunit-console C:\MyApp\Main\MyApp.SeleniumTests\bin\Debug\MyApp.seleniumTests.dll /result=c:\TestRunner\SeleniumResults.xml /noshadow
    
    rem Close IISExpress
    taskkill /IM iisexpress.exe