我用Java编写,基本上测试了一堆东西的节目......干涸的Java(lambda函数?)
对于每一个电话,我需要检查NullPointerExceptions
,StackOverflow
,IndexOutOfBounds
等。 ..
我在我的每一个方法现在这个重复模式:
try {
doSomething();
} catch(NullPointerExceptions npe) {
// prints something
} catch(StackOverflow soe) {
// prints something
} catch(IndexOutOfBounds iob) {
// prints something
}
由于我可以调用doSomething()
(具有不同PARAMS)多次在一个单一的方法,我不能只是throw
的EXC eption备份到主要(因为我需要下一个测试来实际运行)。
我想写一个lambda测试,我可以传递给一个函数,但我不能找到一种方法,用java :(做到这一点
我想这样做:
private void test(Method m, E expectedValue) {
try {
if(!m.run().equals(expectedValue))
System.out.println("FAILED TEST: "+m.name()+". Value was "+m.run()+", should have been "+expectedValue);
} catch() {
// see above
}
}
你可以使用JUnit吗?这对你来说或多或少。 – RoflcoptrException 2011-03-27 17:25:53
不,JUnit在这种情况下是不可行的,否则我会使用它... – sethvargo 2011-03-27 17:30:04
我不明白这个问题。也不明白为什么JUnit不适合。 – Bozho 2011-03-27 17:32:46