Issue
I have a method for which the return type is object. How do I create a test case for this? How do I mention that the result should be an object?
e.g.:
public Expression getFilter(String expo)
{
// do something
return object;
}
Solution
try Something like this. If the return-type of your function is Object
then replace Expression
by Object
:
//if you are using JUnit4 add in the @Test annotation, JUnit3 works without it.
//@Test
public void testGetFilter(){
try {
Expression myReturnedObject = getFilter("testString");
assertNotNull(myReturnedObject); //check if the object is != null
//check if the returned object is of class Expression.
assertTrue(true, myReturnedObject instanceof Expression);
} catch(Exception e){
// let the test fail, if your function throws an Exception.
fail("got Exception, i want an Expression");
}
}
Answered By - Simulant