Hi
I did a very simple test. Class:
public class Car
{
private int ServiceDistance = 15000;
public int Mileage { get; set; }
public int DistanceToService()
{
return Mileage % ServiceDistance;
}
}
Two unit tests:
[TestMethod]
public void NotMockedTest()
{
Car myCar = new Car();
myCar.Mileage = 35000;
int distance = myCar.DistanceToService();
Assert.AreEqual(5000, distance);
}
[TestMethod]
[Isolated]
public void MockedTest()
{
Car myCarFake = Isolate.Fake.Instance<Car>(Members.CallOriginal);
Isolate.WhenCalled(() => myCarFake.Mileage).WillReturn(40000);
int distance = myCarFake.DistanceToService();
Assert.AreEqual(10000, distance);
}
Results:
Visual Studio 2010
Tests run by "Run All Tests in Solution" option. Both tests passed.
MSTest.exe
"C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEMSTest.exe" /noisolation /testcontaine
r:"TypeMockTest.TestsinDebugTypeMockTest.Tests.dll"
Results Top Level Tests
------- ---------------
Failed TypeMockTest.Tests.CarTest.MockedTest
Passed TypeMockTest.Tests.CarTest.NotMockedTest
MSTest.exe using TMockRunner.exe
"c:Program Files (x86)TypemockIsolator.0TMockRunner.exe" "C:Program Files (x86)Microsoft Visual
Studio 10.0Common7IDEMSTest.exe" /noisolation /testcontainer:"TypeMockTest.TestsinDebugTypeMockTest.Tests.dll"
Results Top Level Tests
------- ---------------
Passed TypeMockTest.Tests.CarTest.MockedTest
Passed TypeMockTest.Tests.CarTest.NotMockedTest
NCover.Console using TMockRunner.exe
"c:Program Files (x86)TypemockIsolator.0TMockRunner.exe" -first -link NCover3.0 "c:Program Files
(x86)NCoverNCover.Console.exe" "C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEMSTest.exe" /noisolation /testcontainer:"TypeMockTest.Tests
inDebugTypeMockTest.Tests.dll"
Results Top Level Tests
------- ---------------
Passed TypeMockTest.Tests.CarTest.MockedTest
Passed TypeMockTest.Tests.CarTest.NotMockedTest
No data was collected
For more information on this error, see http://www.ncover.com/lt/no-data
NCover.Console is returning exit code #20000
No coverage was collected.
NCover.Console with //reg using TMockRunner.exe
"c:Program Files (x86)TypemockIsolator.0TMockRunner.exe" -first -link NCover3.0 "c:Program Files
(x86)NCoverNCover.Console.exe" //reg "C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEMSTest.exe" /noisolation /testcontainer:"TypeMockTest.T
estsinDebugTypeMockTest.Tests.dll"
Results Top Level Tests
------- ---------------
Failed TypeMockTest.Tests.CarTest.MockedTest
Passed TypeMockTest.Tests.CarTest.NotMockedTest
Execution Time: 2.9323 s
Symbol Coverage: 61.11%
Branch Coverage: 3.38%
Coverage collected but mocked test failed.
Looks like there is a conflict between those two.
Ncover Explorer
Parameters
Path to application:
c:Program Files (x86)TypemockIsolator.0TMockRunner.exe
Arguments for the application to profile:
-first -link NCover3.0 "C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEMSTest.exe" /noisolation /testcontainer:"TypeMockTest.TestsinDebugTypeMockTest.Tests.dll"
Register NCover before running checked
Register NCover before globally checked
Mocked test fails.
Error in output:
TMockRunner.exe is returning exit code #1
Build script
Works fine. Tests are passing and coverage is collected.
Summary
I'm unable to get test coverage using NCover, neither console or explorer. Although the build script works, it is not an ideal solution. My devs are using NCover Explorer to run tests and work with coverage data and running the script makes things more painful.
Q1:
So, how I can make NEcover explorer working directly without a need to run the script. At this moment the script is the only option that works.
Q2:
I have to find out why my project tests are failing when run outside of Visual Studio. Any hints? I'm creatign mock objects in TestInitialize method. Can that be the reason?[/code]
Update
I've just noticed that I have the following error when run my project tests with MSTest using TMockRunner:
Test method Symantec.Applications.AuthenticationManager.Clients.Tests.ActiveTest.GetSaml2SecurityToken_Saml2SecurityToken_ReturnSaml2SecurityToken_Test threw exception:
TypeMock.TypeMockException:
*** Typemock Isolator is not currently enabled.
To enable do one of the following:
* To run Typemock Isolator as part of an automated process you can:
- run tests via TMockRunner.exe command line tool
- use 'TypeMockStart' tasks for MSBuild or NAnt
* To work with Typemock Isolator inside Visual Studio.NET:
set Tools->Enable Typemock Isolator from within Visual Studio
For more information consult the documentation (see 'Running' topic)
The command line used here is:
"c:Program Files (x86)TypemockIsolator.0TMockRunner.exe" -first "C:Program Files (x86)Microsoft Visual Studio
10.0Common7IDEMSTest.exe" /noisolation /testcontainer:"ClientTestsinDebugSymantec.Applications.AuthenticationManager.Clients.Tests.dll"
To make it more bizarre, tests are fine when I removed /noisolation and -first parameters.