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'm using Visual Studio 2005 Team Edition for Software Developers. I'm using their unit testing framework along side of typemock for mocking.

When I use AlwaysThrow() or ExpectAndThrow() to throw an exception, it doesn't throw the exception type that I'm throwing, like ApplicationException. It instead throws a TypeMockException.

I'm telling VS to expect an exception so that the test doesn't fail, uisng [ExpectedException(ApplicationException)] above the test method signature. If I stick in TypeMockException instead of ApplicationException the test passes. But if I do that, then the test will pass if any TypeMockException is thrown regardless of whether it is valid or not. Am I doing something wrong here?
asked by repairman2003 (1.7k points)

3 Answers

0 votes
Hi
The methods for throwing exceptions shouldn't throw TypeMockException.
TypeMockException is thrown when there's a problem in the test code.

Can you please post test code and the full message from TypeMock exception?
answered by ohad (35.4k points)
0 votes
hmm... It's passing now. But only if I get rid of the previous test. It uses the same mocked classes and it failed when the first mocked object was being created. I never actually stepped through the code line by line since the code is basically is the same except the exception throwing. Though now I don't understand why creating the same objects in a different method should throw a typemock exception.

Mock<DataConnection> dbConn = MockManager.MockAll<DataConnection>(Constructor.Mocked);

As soon as it hits that line it fails, but works fine in the previous method.
answered by repairman2003 (1.7k points)
0 votes
Ah the MockManager needed to be cleared out
answered by repairman2003 (1.7k points)
...