栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

测试期望异常,抛出异常(在输出中显示),但是测试仍然失败

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

测试期望异常,抛出异常(在输出中显示),但是测试仍然失败

在您的方法中,您正在捕获异常并记录消息(这是一种不好的做法,应记录堆栈跟踪),并且在测试中您声明测试的执行 必须
抛出a,

be.vdab.util.mens.MensException
而不会被捕获。

只是重新抛出它,或者根本不将其捕获在要测试的方法/构造函数中。

选项1:

public Voertuig() {    this.nummerplaat = div.getNummerplaat();    this.Zitplaatsen = Zitplaatsen;    try {        //...        //pre in the try...        //...    } catch (MensException e) {        //System.out.println(e.getMessage());        //use a logger, not System.out        //in case you still want to use System.out        //then at least use the pre shown below        //e.printStackTrace(System.out);        //line above commented since there's no need to log        //and rethrow the exception        //the exception will be handled by the highest level execution        //and there it should be logged or use another strategy        throw e;    } }

选项2:

public Voertuig() {    this.nummerplaat = div.getNummerplaat();    this.Zitplaatsen = Zitplaatsen;//remove the try//    try {    //...    //pre in the try...    //...//remove the catch//    } catch (MensException e) {//        System.out.println(e.getMessage());//    } }

IMO我将使用选项2而不是选项1。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/410531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号