为Java代码定义测试数据-简单-也许使用Scala?
|
是否有可能为Java程序定义一些测试数据,从而使其易于人类阅读并可以通过编程方式解析为相关的函数调用和数据元素。
如果不可能,请使用Java实现此目的,因此我愿意使用Scala。被测试的代码是Java代码,并且不会移植到Scala。
interface someInterface {
class X {
// the member variables will always either
// be enums or intrinsic types
private int a;
public int a() { return this.a; };
public void a(int a) {this.a = a; };
private double b;
public double b() { return this.b; };
public void b(double b) {this.b = b; };
private String c;
public String c() { return this.c; };
public void c(String c) {this.c = c; };
}
enum A {
A_1,
A_2
}
class Y {
// assume setters and getters as per X above
private A a;
private double b;
private String c;
private Z[] z;
}
class Z {
private int a;
private double b;
private String c;
}
Y function1(X x, String s);
}
public void boo() {
String[] testData = {
/* how can I specify this array so that
coo(...) can be called as below
would I be better off defining this
test code in Scala?
the classes and interfaces above:
someInterface, A, X, Y and Z are in Java
and will not be ported to Scala */
};
coo(testData);
}
public void coo(String[] testData) {
/* this function will know how to:
a) parse testData
b) use reflection to call
someInterface.functionXXX with parameters
as specified in testData
c) construct the return result as specified
in testData and compare against actual
return result */
}
}
没有找到相关结果
已邀请:
2 个回复
掸牛浓疗
并与
类一起运行。 创建一个这样的测试类:
解释:
告诉JUnit框架运行,向测试类询问参数,并使用这些参数运行该类中的所有测试。 期望
等于
。每个“ 6”通过反射传递到此类的构造函数。
-提供您要测试的所有方案。 在特定参数集上运行所有测试之前,“ 9”将填充此类的成员。重要的是要注意\ someInterface`仅初始化一次-对于每个参数集。如果您为同一参数集添加更多测试,则可能需要重新初始化它。
运行测试。
提供的ѭ6将运行一次。并且保证在执行
之后运行(run,就像您在这里有其他选择一样)
闲窍