I am doing code coverage testing in Jmockit.When I was trying to cover an exception block in a class file with the code below
new NonStrictExpectations(){
{
someObject.executeProcedure("sometext",new ArrayList<SomeType>(),new SomeClass());
result=new ApplicationrunTimeException();
}
};
The exception block is not covered and the above code doesn't work.Whereas the code with slight modifications as shown below works well
new NonStrictExpectations(){
{
someObject.executeProcedure(anystring, (List<SomeType>)any,(SomeClass)any);
result=new ApplicationrunTimeException();
}
};
I dont know why is it so... The actual code in the class file is
try
{
anotherObject=someObject.executeProcedure(SomeClass.STRING, someList,someClass);
}
catch(ApplicationrunTimeException exp)
{
}
in which SomeClass.STRING is a string,someList is of type List & someClass is a class variable..
I just want to know the usage of things like anyString,anyInt,any in Jmockit and in what way it differs from a valid string,integer and an object.
When your test runs SomeClass.STRING must not be equal to "sometext".
If you pass the string "sometext" into the method in the expectations block, then this is the value that must be provided during code runtime in order for the expectation to be invoked. Using anyString works because it will match any string.