Jes*_*sie 3 java junit object testcase
我有一个方法,其返回类型是对象。我如何为此创建一个测试用例?我如何提及结果应该是一个对象?
例如:
public Expression getFilter(String expo)
{
// do something
return object;
}
Run Code Online (Sandbox Code Playgroud)
尝试这样的事情。如果函数的返回类型Object替换Expression为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");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
31755 次 |
| 最近记录: |