How to get the result of a Junit assertEquals test and put it into a String variable?

Asked

Viewed 3,707 times

0

I have a Junit test case to test a single class. The class to be tested contains only one "sum" method that sums two numbers. To test if it is correct, I use the following method: Assert.assertEquals(2, meu_objeto.sum(1, 2)); The result appears in a Junit tab in the eclipse, in a part called Failure Trace. The message says: junit.framework.AssertionFailedError: expected:<2> but was:<3> You can take this message and place it inside a String variable?

  • tries to capture with Try/catch

  • I’ve tried, @user5978. I can’t get any results from this.

  • http://junit.sourceforge.net/junit3.8.1/javadoc/junit/framework/AssertionFailedError.html. Apparently there’s a method: getMessage, try it, if you haven’t tried it already.

  • Junit can be extended in some ways, if your need is worth the effort... But suddenly there are simpler alternatives. For what you need to get this message in a string?

  • user5978, I couldn’t use getMessage. @Caffé I need to make a class evaluation system using Junit, and I need this message to appear in a notification window for the user.

1 answer

2


Browser other questions tagged

You are not signed in. Login or sign up in order to post.