mercredi 30 septembre 2015

How to test exception in void method? [duplicate]

This question already has an answer here:

For example I have the following method....

private Trace trace = new Trace();
private TracertImpl tracert = new TracertImpl(); 

public void msg(){

        message.add("Result : " +result);
        try {
            trace.add(tracert.BuildMessage(MessageType.New,
                    wayPoint, CastLevel.B , "Cast " + cast.id
                            + " reason: " + msg));
        } catch (Exception e) {
            log.error("CONSTR: "
                    + " Call to tracert.BuildMessage threw exception.", e);
        }
}

My team wants 100% coverage but the case that exception cant be reached unless tracert = null and I was thinking are there any other way to cover exception?

Aucun commentaire:

Enregistrer un commentaire