Hi,
I am trying to run the unit test for my .net 6 and want to see the code coverage using "Analyse Code Coverage for all Tests" in VS2022.
it successfully run all all test cases when I "run all Tests" but when I use "Analyse Code Coverage for all Tests" to run and see the code coverage, there are some test case failed throwing ThrowElevatedMockingException as below.
Message:
Telerik.JustMock.Core.ElevatedMockingException : Cannot mock 'System.Threading.Tasks.Task`1[System.Collections.Generic.List`1[AppHub.SingleView.AmazonFireStickPromo.Models.AccountPromoToken]] GetAccountPromoTokensAsync(System.String)'. The profiler must be enabled to mock, arrange or execute the specified target.
Detected active third-party profilers:
* {324F817A-7420-4E6D-B3C1-143FBED6D855} (from process environment)
Disable the profilers or link them from the JustMock configuration utility. Restart the test runner and, if necessary, Visual Studio after linking.
Stack Trace:
ProfilerInterceptor.ThrowElevatedMockingException(MemberInfo member)
MocksRepository.CheckMethodInterceptorAvailable(IMatcher instanceMatcher, MethodBase method)
MocksRepository.AddArrange(IMethodMock methodMock)
MocksRepository.Arrange[TMethodMock](Object instance, MethodBase method, Object[] arguments, Func`1 methodMockFactory)
<>c__DisplayClass24_0`1.<Arrange>b__0()
ProfilerInterceptor.GuardInternal[T](Func`1 guardedAction)
NonPublicExpectation.Arrange[TReturn](Object target, String memberName, Object[] args)
PromoCodeManagementServiceTests.GetAllEmailStatusesAsync_WithTokenFromAccount_ExpectedListEmailStatus() line 145
GenericAdapter`1.GetResult()
AsyncToSyncAdapter.Await(Func`1 invoke)
TestMethodCommand.RunTestMethod(TestExecutionContext context)
TestMethodCommand.Execute(TestExecutionContext context)
<>c__DisplayClass1_0.<Execute>b__0()
DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
I think run all test is successful as I use specify env.runsettings in my project file (attached file).
but the test run in "Analyse Code Coverage for all Tests" failed in some methods.
Package I used
<PackageReference Include="JustMock.Commercial" Version="2023.1.117.1" />
Can someone help me to fix this one ?
Thanks
I want the Mock to return the SQL statement and Not execute the statement. This is what i have done but it keeps running the "connection.execution(SQL)".
string SQL = "";
Mock.Arrange(() => connection.Execute(Arg.AnyString, null, null, null, null)).DoInstead((string arg1) => { SQL = arg1; }).IgnoreInstance().Returns(1);
WebApiProject.Controllers.DeleteController dc = new WebApiProject.Controllers.DeleteController();
dc.Post(mockedDeleteObject);
Assert.IsTrue(SQL == $"DELETE FROM TEST WHERE 1=1");
Post{
string SQL;
SQL = $"delete from {TableName} where {WhereClause} ";
con.Execute(SQL,parameters );}
But it keeps running the sql executable statement
Hi Team
We tried executing justMock test cases in command prompt using justMock Console (licensed), dotCover and xUnit, but justMock Test execution failed and gave the error "System.InvalidProgramException : Common Language Runtime detected an invalid program."
The command we use to execute is as follows:
start /wait "" "{PATH}\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /link "dotCover"
"{PATH}\JustMock\Libraries\Telerik.JustMock.Console.exe" runadvanced --profiler-path-64 "{PATH}\JustMock\Libraries\CodeWeaver\64\Telerik.CodeWeaver.Profiler.dll" --command "{PATH}\JetBrains.dotCover.CommandLineTools.2021.1.3\dotCover.exe" --command-args "cover --reporttype=html --output=CodeCoverage\\index.html --targetexecutable=\"{PATH}\xunit.runner.console.2.4.1\tools\net472\xunit.console.exe\" -- \"{PATH}\{PATH_OF_JUSTMOCK_TEST_DLL}\""
start /wait "" "{PATH}\JustMock\Libraries\Telerik.JustMock.Configuration.exe" /unlink "dotCover"
Attaching the log and test code.