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;
}
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");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With