Testing the Impossible: Asserting Several Values At Once

So you want to check several values at once, maybe because that helps you to locate the error more easily. Simple:

int v1 = list1.size();
int v2 = list2.size();
int v3 = list3.size();

assertEquals (
      "list1=5\n"
    + "list2=2\n"
    + "list3=0\n"
    , "list1="+v1+"\n"
    + "list2="+v2+"\n"
    + "list3="+v3+"\n"

2 Responses to Testing the Impossible: Asserting Several Values At Once

  1. […] In the asserts, just collect all the results into a big String and compare them all at once. […]

  2. […] Testing the Impossible: Shifting IDs 7. October, 2009 at 09:38 | In Software | Leave a Comment Tags: Database, Hibernate, ID, Java, Spring, Testing So you couldn’t resist and wrote tests against the database. With Hibernate, no less. And maybe some Spring. And to make things more simple, toString() contains the IDs of the objects in the database. Now, you want to check the results of queries and other operations using my advice how to verify several values at once. […]

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.