我已经有一些java代码的集成测试,我想知道是否有任何方法来检测每个集成测试的源和目标,例如,如果我们有两个组件A和B,当组件A调用组件B时,我们应该有一个集成测试来一起测试这两个组件,当组件B调用组件A时,我们应该有另一个集成测试,我的问题是从测试用例代码中,我们是否可以通过使用工具或特定的库来自动决定哪个组件是调用者,哪个是被调用者。
public void GetPatientInfo() //testGetPatientInfo()
{
ArrayList<PatientInfo> patients = new ArrayList<PatientInfo>();
String pid = "10";
EMRService instance = new EMRService();
instance.setPatients(patients);
PatientInfo p=new PatientInfo( "10", "ali", 120, 200);
patients.add(p);
PatientInfo expResult = p;
PatientInfo result = instance.getPatientInfo(pid);
assertEquals(expResult, result);
}发布于 2011-10-19 02:59:10
您可以使用instanceof操作符来确定类类型。
假设您的类层次结构如下:
interface Component { public void foo(Component bar); }
class A implements Component {}
class B implements Component {}您的函数可能如下所示:
public void foo(Component bar)
{
if(bar instanceof A)
// do one type of intergration tests
else if(bar is instanceof B)
// do other type of integration tests
}另一种可能是将AOP与周围建议一起使用,或者使用mock。如果您提供更多信息(例如示例函数调用),我也许能够提供更好的答案。
通常你会写两个不同的集成测试,一个假设函数是用A类调用的,另一个是用B类调用的。
https://stackoverflow.com/questions/7811941
复制相似问题