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



