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
0 votes

BELOW ELSE CONDITION  I AM GETTING EXCEPTION DIALOG. I NEED TO MOCK EXCEPTION DIALOG WHEN RUNING THE TESTING?

public void Set(Info di)

{

if (Dir == null)

{

                Dir = di;

}

else

{

Logger.Instance.LogString("xxxx " + "YYYYYY.");

throw new InvalidOperationException("YYYYY." + " XXX");

}

}

asked by gnanam (4.7k points)

1 Answer

0 votes
Hey Gnanam,

Is it a part of your code? Would you like that the program will throw an exception when the \"else\" part execute?

if your answer to this is yes, then I suggest to create 2 different tests. One test will be dedicated to the \"if\" statement and the other to \"else\". In order for the test to pass when an exception is thrown, the following attribute needs to be added at the top of the specific method:

 [ExpectedException(typeof(InvalidOperationException)),\" your message\"]

P.S The string part is not mandatory.

Hope I understood correctly.

Please feel free to write to us.

Cheers,

Coral
answered by CoralTypemock (940 points)
Hey gnanam,

Did my suggestion answer your question?

Please let us know if you need further assistance.

Cheers,

Coral
...