Re: [easytesting] Customized Assertion Errors in 2.x

15 views
Skip to first unread message

Alex Ruiz

unread,
Mar 15, 2013, 4:39:18 PM3/15/13
to easytesting
Gary,

I'm really not happy with the way we allow custom errors in the API. It was confusing in the sense that it has to be at the right place in the fluent interface. Reading code was not so intuitive either. So far, I haven't found a good way to reintroduce this feature. One idea is to have a registry of formatters that know how to create a String representation of objects. This registry will be used outside of the fluent interface though.

I'm open for suggestions.

Thanks,
-Alex


On Wed, Mar 6, 2013 at 6:42 PM, Gary Affonso <ga...@teahousesoftware.com> wrote:
What are the customization options for assertion errors in 2.x?  I saw that the 1.x series had some inline options and that this feature is no longer available in 2.x.  Googling has not turned up an alternative solution for 2.x so here I am.

What's my use case?  This one...

    @Test
    public void VerifyGoldMasterContentForListOfFoo() throws IOException
    {
        OAuth2RestTemplate restTemplate = anOauth2RestTemplateBuilder().withValidClientCredentials().build();
        String response = restTemplate.getForObject(BASE_URL, String.class);

        JSONObject jsonObject = JSONObject.fromObject(response);
        String goldMasterResponse = getFileContent("/gold-master-responses/list-of-foo.json");
        assert(jsonObject).equals(JSONObject.fromObject(goldMasterResponse));
    }

The error response if the two JSONObjects are not-equal is...

java.lang.AssertionError
at com.foo.morpheus.functional.ApiGoldMasterTest.VerifyGoldMasterContentForListOfExercisers(ApiGoldMasterTest.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
...

I'm happy with the equality algorithm of the JSONObject, I just want a better error-message when equality fails in an assertion (an error message that includes the content of the JSONObject).

Suggestions?

Thanks!

Gary

--
You received this message because you are subscribed to the Google Groups "easytesting" group.
To unsubscribe from this group and stop receiving emails from it, send an email to easytesting...@googlegroups.com.
To post to this group, send email to easyt...@googlegroups.com.
Visit this group at http://groups.google.com/group/easytesting?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages