北大青鸟accp50前沿技术课(编辑修改稿)内容摘要:

个 @Test注记 _2 测试驱动的框架程序(后面详述代码机制) public class RunTests { public static void main(String[] args) throws Exception { int passed = 0, failed = 0。 for (Method m : (args[0]).getMethods()) { if (()) { try { (null)。 passed++。 } catch (Throwable ex) { ... 运行结果 Test public static void () failed: : Boom Test public static void () failed: : Crash Passed: 2, Failed 2 14 自定义一个 @Test注记 _3 原理 @Retention表明 @Test注记在单元测试 运行时 产生作用 @Target表明 @Test注记附加在单元测试的 方法 上 import .*。 @Retention() @Target() public @interface Test { } 注记定义为一个接口 15 自定义一个 @Test注记 _4 测试驱动框架程序原理 (args[0]).getMethods()返回 Method[ ] 使用 foreach遍历 Method数组,检查方法是否具有 @Test注记。 如果具有 @Test注记, (null)将调用此静态方法。 public class RunTests { public static void main(String[] args) throws Exception { int passed = 0, failed = 0。 for (Method m : (args[0]).getMethods()){ if (()) { try { (null)。 passed++。 } catch (Throwable ex) { … 16 自定义一个 @Test注记 _5 NetBeans中设定工程的 Run特性 设定工程的启动配置,将被测的程序 Foo作为 RunTests的 args[0] 17。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。