站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Eclipse 专题Eclipse插件Continuous Testing-持续测试将错误扼杀在摇篮之中

Eclipse插件Continuous Testing-持续测试将错误扼杀在摇篮之中

摘要: Eclipse插件Continuous Testing-持续测试将错误扼杀在摇篮之中

package test; import java.util.Arrays; import junit.framework.TestCase; public class DummyTest extends TestCase { public void testTopThreeIntsUnsorted() { Integer one = new Integer(1); Integer two = new Integer(2); Integer three = new Integer(3); Integer four = new Integer(4); Integer five = new Integer(5); Integer six = new Integer(6); assertEquals(Arrays.asList(new Integer[] { one, two, three }), Arrays .asList(new Integer[] { four, five, six })); } public void testException() throws Exception { throw new IllegalArgumentException(); } } </td></tr></table>

Continuous Testing插件在后台执行测试代码,当监测到有错误或异常发生,Continuous Testing将会通过Problem View来通知开发人员。在我们提供的测试用例中,Problem View将会如下所示:


图 4 Problem View

如果我们在Problem View当中双击某一条测试错误信息,那么Java编辑器将会打开并显示产生错误的测试方法。这和我们察看其他错误发生地点的方式非常象,不是吗?另外,如果我们在编辑器中打开了DummyTest.java,我们还可以看到新的测试错误标记出现在编辑器的左侧栏上。


图 5 编辑器上的测试错误标记

通过上面的描述我们可以看到,使用Continuous Testing的方式非常简单。Continuous Testing插件甚至没有引入任何新的视图。我们工作的方式与以往完全一样,仅有的不同是现在Eclipse在IDE中自动显示测试错误信息。

对多Project的支持

当使用JUnit进行测试时,我们通常将测试放置在一个单独的工程中。这种情况下,我们需要对工程进行一些特殊的配置。假如我们将hello工程的Test Case放置在工程hello.test中,那么当我们为hello工程起用Continuous Testing支持时,需要按照图 1配置hello工程的Continuous Testing属性。


图 6 多工程情况下配置测试

也就是说我们需要改变Continuous Testing查找Test Case的方法,使得当hello工程被修改时,Continuous Testing从工程hello.test中寻找测试用例。

除了多Project支持之外,Continuous Testing还支持其他一些高级特性例如howswap、低优先级执行、remote executeon等。感兴趣的读者朋友可以进一步对其进行研究。

小结

通过使用Continuous Testing,我们能够在修改代码的同时对代码的逻辑正确性进行检查。如果说Eclipse的增量编译功能使得我们在修改代码的同时能获得对代码语法正确性的信心,那么Continuous Testing能帮助我们获得对代码逻辑正确性的信心。这两者的结合,能够使得我们的软件编写出现更少的错误,同时,也能够最大限度的减轻我们修正错误所需的代价。

参考资料



↑返回目录
前一篇: eclipse财务管理小插件
后一篇: eclipse超cool新特性--JFace Data Binding