chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
I have written test for a clas, for Ncover
I made two test files, one of my test class file contain test that are not nocked and other file contain mocked test for that file.
When i run mocked test only then its working fine but when i run all test, mocked and unmocked then mocking is not working.

Please help me its very urgent
asked by prsh (1.7k points)

3 Answers

0 votes
Are you using an Enterprise Edition (see this topic)?

Please tell me what results you are getting.
answered by scott (32k points)
0 votes
I am using community edition.

When i run test(Mocked and Unmocked) then Mocking on Mock test not working.
Example:
function()
{
try
{
MyClass.function2();
}
catch(Exception ex)
{
throw ex;
}
}

I want to cover my exception block(Catch)
for that i have written a mock test.
[Test]
public void FucntionTest()
{
MockManager.Init();
Mock MyClassMock = mockManager.Mock(typeof(MyClass));
MyClassMock.ExpectAndThrow("function2", new Exception);
function();
MyClassMock.Clear();
MyClassMock.Verify();
MockManager.Verify()
}
answered by prsh (1.7k points)
0 votes
It is very hard to understand what is happening as your code doesn't compile and you are not sending what you expect to happen and what is actually happening.

If I understand your test, your function() shoudl throw the error so your test will never pass the function() call.
To check use the [ExpectedException(typeof(Exception))] attribute
or use the following pattern:
[Test] 
{ 
    <setuptest here>
    try {
      function();
      Asset.Fail("Should throw Exception");
    } catch (Exception ex) {
      <validate ex here>
    }
}
answered by scott (32k points)
...