[libsoup] tests: initial port to the gtestutils framework



commit 64e667bda5009c8f1acd03659c457e26b16457a6
Author: Dan Winship <danw gnome org>
Date:   Tue Dec 10 15:47:34 2013 +0100

    tests: initial port to the gtestutils framework
    
    Some programs need to be split up into more tests, and the debug
    output is mostly not updated for the new format.

 tests/auth-test.c          |  288 ++++++++++++----------------------
 tests/cache-test.c         |  214 ++++++++------------------
 tests/chunk-io-test.c      |  122 +++++----------
 tests/chunk-test.c         |  162 +++++++-------------
 tests/coding-test.c        |  179 +++++++++-------------
 tests/connection-test.c    |  283 +++++++++++-----------------------
 tests/context-test.c       |   84 ++++------
 tests/continue-test.c      |   32 ++--
 tests/cookies-test.c       |   69 +++------
 tests/date.c               |  194 +++++++++++------------
 tests/forms-test.c         |   69 +++------
 tests/header-parsing.c     |  276 +++++++---------------------------
 tests/misc-test.c          |  232 ++++++++---------------------
 tests/multipart-test.c     |  226 +++++++++-------------------
 tests/no-ssl-test.c        |   98 ++++---------
 tests/ntlm-test.c          |  175 ++++++++++-----------
 tests/proxy-test.c         |  190 ++++++++---------------
 tests/pull-api.c           |  170 ++++++++++-----------
 tests/range-test.c         |  140 ++++++++----------
 tests/redirect-test.c      |  267 ++++++++++++++------------------
 tests/requester-test.c     |  349 ++++++++++++++++--------------------------
 tests/resource-test.c      |  163 ++++++++------------
 tests/server-auth-test.c   |   55 ++-----
 tests/server-test.c        |  108 ++++----------
 tests/session-test.c       |  146 +++++++-----------
 tests/sniffing-test.c      |  324 +++++++++++++++++++--------------------
 tests/socket-test.c        |   71 +++++----
 tests/ssl-test.c           |  229 ++++++++++------------------
 tests/streaming-test.c     |   61 +++++---
 tests/test-utils.c         |   77 ++++------
 tests/test-utils.h         |   68 +++++++--
 tests/timeout-test.c       |  187 +++++++++++------------
 tests/tld-test.c           |  311 +++++++++++++++++++------------------
 tests/uri-parsing.c        |  365 ++++++++++++++------------------------------
 tests/xmlrpc-server-test.c |   43 ++++--
 tests/xmlrpc-test.c        |  214 ++++++++++----------------
 36 files changed, 2392 insertions(+), 3849 deletions(-)
---
diff --git a/tests/auth-test.c b/tests/auth-test.c
index 992e3d5..c182520 100644
--- a/tests/auth-test.c
+++ b/tests/auth-test.c
@@ -4,6 +4,7 @@
 
 #ifdef HAVE_APACHE
 
+static const char *base_uri;
 static GMainLoop *loop;
 
 typedef struct {
@@ -37,10 +38,6 @@ typedef struct {
        guint final_status;
 } SoupAuthTest;
 
-/* Will either point to main_tests or relogin_tests
- */
-static SoupAuthTest *current_tests;
-
 static SoupAuthTest main_tests[] = {
        { "No auth available, should fail",
          "Basic/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
@@ -151,7 +148,9 @@ static SoupAuthTest main_tests[] = {
          "Digest/realm1/", "", FALSE, "0", SOUP_STATUS_UNAUTHORIZED },
 
        { "Fail with URI-embedded password, then use right password in the authenticate signal",
-         "Basic/realm3/", "43", TRUE, "43", SOUP_STATUS_OK }
+         "Basic/realm3/", "43", TRUE, "43", SOUP_STATUS_OK },
+
+       { NULL }
 };
 
 static const char *auths[] = {
@@ -207,14 +206,12 @@ handler (SoupMessage *msg, gpointer data)
 
        if (*expected) {
                exp = *expected - '0';
-               if (auth != exp) {
-                       debug_printf (1, "    expected %s!\n", auths[exp]);
-                       errors++;
-               }
+               soup_test_assert (auth == exp,
+                                 "expected %s", auths[exp]);
                memmove (expected, expected + 1, strlen (expected));
        } else {
-               debug_printf (1, "    expected to be finished\n");
-               errors++;
+               soup_test_assert (*expected,
+                                 "expected to be finished");
        }
 }
 
@@ -222,18 +219,18 @@ static void
 authenticate (SoupSession *session, SoupMessage *msg,
              SoupAuth *auth, gboolean retrying, gpointer data)
 {
-       int *i = data;
+       SoupAuthTest *test = data;
        char *username, *password;
        char num;
 
-       if (!current_tests[*i].provided[0])
+       if (!test->provided[0])
                return;
        if (retrying) {
-               if (!current_tests[*i].provided[1])
+               if (!test->provided[1])
                        return;
-               num = current_tests[*i].provided[1];
+               num = test->provided[1];
        } else
-               num = current_tests[*i].provided[0];
+               num = test->provided[0];
 
        username = g_strdup_printf ("user%c", num);
        password = g_strdup_printf ("realm%c", num);
@@ -249,13 +246,10 @@ bug271540_sent (SoupMessage *msg, gpointer data)
        gboolean *authenticated = data;
        int auth = identify_auth (msg);
 
-       if (!*authenticated && auth) {
-               debug_printf (1, "    using auth on message %d before authenticating!!??\n", n);
-               errors++;
-       } else if (*authenticated && !auth) {
-               debug_printf (1, "    sent unauthenticated message %d after authenticating!\n", n);
-               errors++;
-       }
+       soup_test_assert (*authenticated || !auth,
+                         "using auth on message %d before authenticating", n);
+       soup_test_assert (!*authenticated || auth,
+                         "sent unauthenticated message %d after authenticating", n);
 }
 
 static void
@@ -274,8 +268,8 @@ bug271540_authenticate (SoupSession *session, SoupMessage *msg,
                soup_auth_authenticate (auth, "user1", "realm1");
                *authenticated = TRUE;
        } else {
-               debug_printf (1, "    asked to authenticate message %d after authenticating!\n", n);
-               errors++;
+               soup_test_assert (!*authenticated,
+                                 "asked to authenticate message %d after authenticating", n);
        }
 }
 
@@ -283,13 +277,8 @@ static void
 bug271540_finished (SoupSession *session, SoupMessage *msg, gpointer data)
 {
        int *left = data;
-       int n = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (msg), "#"));
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "      got status '%d %s' on message %d!\n",
-                             msg->status_code, msg->reason_phrase, n);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        (*left)--;
        if (!*left)
@@ -297,7 +286,7 @@ bug271540_finished (SoupSession *session, SoupMessage *msg, gpointer data)
 }
 
 static void
-do_pipelined_auth_test (const char *base_uri)
+do_pipelined_auth_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
@@ -442,23 +431,16 @@ do_digest_nonce_test (SoupSession *session,
                                              &got_401);
        got_401 = FALSE;
        soup_session_send_message (session, msg);
-       if (got_401 != expect_401) {
-               debug_printf (1, "  %s request %s a 401 Unauthorized!\n", nth,
-                             got_401 ? "got" : "did not get");
-               errors++;
-       }
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "  %s request got status %d %s!\n", nth,
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-       if (errors == 0)
-               debug_printf (1, "  %s request succeeded\n", nth);
+       soup_test_assert (got_401 == expect_401,
+                         "%s request %s a 401 Unauthorized!\n", nth,
+                         got_401 ? "got" : "did not get");
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
        g_object_unref (msg);
 }
 
 static void
-do_digest_expiration_test (const char *base_uri)
+do_digest_expiration_test (void)
 {
        SoupSession *session;
        char *uri;
@@ -535,10 +517,8 @@ async_authenticate_assert_once (SoupSession *session, SoupMessage *msg,
 
        debug_printf (2, "  async_authenticate_assert_once\n");
 
-       if (*been_here) {
-               debug_printf (1, "  ERROR: async_authenticate_assert_once called twice\n");
-               errors++;
-       }
+       soup_test_assert (!*been_here,
+                         "async_authenticate_assert_once called twice");
        *been_here = TRUE;
 }
 
@@ -550,10 +530,8 @@ async_authenticate_assert_once_and_stop (SoupSession *session, SoupMessage *msg,
 
        debug_printf (2, "  async_authenticate_assert_once_and_stop\n");
 
-       if (*been_here) {
-               debug_printf (1, "  ERROR: async_authenticate_assert_once called twice\n");
-               errors++;
-       }
+       soup_test_assert (!*been_here,
+                         "async_authenticate_assert_once called twice");
        *been_here = TRUE;
 
        soup_session_pause_message (session, msg);
@@ -561,7 +539,7 @@ async_authenticate_assert_once_and_stop (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-do_async_auth_test (const char *base_uri)
+do_async_auth_test (void)
 {
        SoupSession *session;
        SoupMessage *msg1, *msg2, *msg3, msg2_bak;
@@ -595,13 +573,7 @@ do_async_auth_test (const char *base_uri)
        g_object_set_data (G_OBJECT (msg2), "id", GINT_TO_POINTER (2));
        soup_session_send_message (session, msg2);
 
-       if (msg2->status_code == SOUP_STATUS_UNAUTHORIZED)
-               debug_printf (1, "  msg2 failed as expected\n");
-       else {
-               debug_printf (1, "  msg2 got wrong status! (%u)\n",
-                             msg2->status_code);
-               errors++;
-       }
+       soup_test_assert_message_status (msg2, SOUP_STATUS_UNAUTHORIZED);
 
        /* msg2 should be done at this point; assuming everything is
         * working correctly, the session won't look at it again; we
@@ -632,25 +604,11 @@ do_async_auth_test (const char *base_uri)
                g_main_loop_run (loop);
 
                /* async_finished will quit the loop */
-       } else {
-               debug_printf (1, "  msg1 didn't get authenticate signal!\n");
-               errors++;
-       }
+       } else
+               soup_test_assert (auth, "msg1 didn't get authenticate signal");
 
-       if (msg1->status_code == SOUP_STATUS_OK)
-               debug_printf (1, "  msg1 succeeded\n");
-       else {
-               debug_printf (1, "  msg1 FAILED! (%u %s)\n",
-                             msg1->status_code, msg1->reason_phrase);
-               errors++;
-       }
-       if (msg3->status_code == SOUP_STATUS_OK)
-               debug_printf (1, "  msg3 succeeded\n");
-       else {
-               debug_printf (1, "  msg3 FAILED! (%u %s)\n",
-                             msg3->status_code, msg3->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg1, SOUP_STATUS_OK);
+       soup_test_assert_message_status (msg3, SOUP_STATUS_OK);
 
        soup_test_session_abort_unref (session);
 
@@ -688,10 +646,8 @@ do_async_auth_test (const char *base_uri)
        g_main_loop_run (loop);
        g_signal_handler_disconnect (session, auth_id);
 
-       if (!been_there) {
-               debug_printf (1, "  authenticate not emitted?\n");
-               errors++;
-       }
+       soup_test_assert (been_there,
+                         "authenticate not emitted");
 
        soup_test_session_abort_unref (session);
        g_object_unref (msg1);
@@ -800,41 +756,27 @@ select_auth_test_one (SoupURI *uri,
        msg = soup_message_new_from_uri ("GET", uri);
        soup_session_send_message (session, msg);
 
-       if (strcmp (sad.round[0].headers, first_headers) != 0) {
-               debug_printf (1, "    Header order wrong: expected %s, got %s\n",
-                             first_headers, sad.round[0].headers);
-               errors++;
-       }
-       if (strcmp (sad.round[0].response, first_response) != 0) {
-               debug_printf (1, "    Selected auth type wrong: expected %s, got %s\n",
-                             first_response, sad.round[0].response);
-               errors++;
-       }
-
-       if (second_headers && !sad.round[1].headers) {
-               debug_printf (1, "    Expected a second round!\n");
-               errors++;
-       } else if (!second_headers && sad.round[1].headers) {
-               debug_printf (1, "    Didn't expect a second round!\n");
-               errors++;
-       } else if (second_headers && second_response) {
-               if (strcmp (sad.round[1].headers, second_headers) != 0) {
-                       debug_printf (1, "    Second round header order wrong: expected %s, got %s\n",
-                                     second_headers, sad.round[1].headers);
-                       errors++;
-               }
-               if (strcmp (sad.round[1].response, second_response) != 0) {
-                       debug_printf (1, "    Second round selected auth type wrong: expected %s, got %s\n",
-                                     second_response, sad.round[1].response);
-                       errors++;
-               }
+       soup_test_assert (strcmp (sad.round[0].headers, first_headers) == 0,
+                         "Header order wrong: expected %s, got %s",
+                         first_headers, sad.round[0].headers);
+       soup_test_assert (strcmp (sad.round[0].response, first_response) == 0,
+                         "Selected auth type wrong: expected %s, got %s",
+                         first_response, sad.round[0].response);
+
+       soup_test_assert (sad.round[1].headers || !second_headers,
+                         "Expected a second round");
+       soup_test_assert (!sad.round[1].headers || second_headers,
+                         "Didn't expect a second round");
+       if (second_headers && second_response) {
+               soup_test_assert (strcmp (sad.round[1].headers, second_headers) == 0,
+                                 "Second round header order wrong: expected %s, got %s\n",
+                                 second_headers, sad.round[1].headers);
+               soup_test_assert (strcmp (sad.round[1].response, second_response) == 0,
+                                 "Second round selected auth type wrong: expected %s, got %s\n",
+                                 second_response, sad.round[1].response);
        }
 
-       if (msg->status_code != final_status) {
-               debug_printf (1, "    Final status wrong: expected %u, got %u\n",
-                             final_status, msg->status_code);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, final_status);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
@@ -1062,12 +1004,7 @@ do_auth_close_test (void)
        soup_uri_free (uri);
        soup_session_send_message (acd.session, acd.msg);
 
-       if (acd.msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    Final status wrong: expected %u, got %u %s\n",
-                             SOUP_STATUS_OK, acd.msg->status_code,
-                             acd.msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (acd.msg, SOUP_STATUS_OK);
 
        g_object_unref (acd.msg);
        soup_test_session_abort_unref (acd.session);
@@ -1089,7 +1026,7 @@ infinite_authenticate (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-do_infinite_auth_test (const char *base_uri)
+do_infinite_auth_test (void)
 {
        SoupSession *session;
        SoupMessage *msg;
@@ -1107,17 +1044,14 @@ do_infinite_auth_test (const char *base_uri)
        g_free (uri);
 
        timeout = g_timeout_add (500, infinite_cancel, session);
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*stuck in infinite loop*");
        soup_session_send_message (session, msg);
+       g_test_assert_expected_messages ();
 
-       if (msg->status_code == SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "    FAILED: Got stuck in loop");
-               errors++;
-       } else if (msg->status_code != SOUP_STATUS_UNAUTHORIZED) {
-               debug_printf (1, "    Final status wrong: expected 401, got %u\n",
-                             msg->status_code);
-               errors++;
-       }
+       soup_test_assert (msg->status_code != SOUP_STATUS_CANCELLED,
+                         "Got stuck in loop");
+       soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
 
        g_source_remove (timeout);
        soup_test_session_abort_unref (session);
@@ -1182,14 +1116,9 @@ do_disappearing_auth_test (void)
        msg = soup_message_new_from_uri ("GET", uri);
        soup_session_send_message (session, msg);
 
-       if (counter > 2) {
-               debug_printf (1, "    FAILED: Got stuck in loop");
-               errors++;
-       } else if (msg->status_code != SOUP_STATUS_UNAUTHORIZED) {
-               debug_printf (1, "    Final status wrong: expected 401, got %u\n",
-                             msg->status_code);
-               errors++;
-       }
+       soup_test_assert (counter <= 2,
+                         "Got stuck in loop");
+       soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
@@ -1220,25 +1149,26 @@ static SoupAuthTest relogin_tests[] = {
 
        { "Should fail with no auth, fail again with bad password, and give up",
          "Basic/realm12/", "3", FALSE, "03", SOUP_STATUS_UNAUTHORIZED },
+
+       { NULL }
 };
 
 static void
-do_batch_tests (const gchar *base_uri_str, gint ntests)
+do_batch_tests (gconstpointer data)
 {
+       const SoupAuthTest *current_tests = data;
        SoupSession *session;
        SoupMessage *msg;
        char *expected, *uristr;
-       SoupURI *base_uri;
+       SoupURI *base;
+       guint signal;
        int i;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       g_signal_connect (session, "authenticate",
-                         G_CALLBACK (authenticate), &i);
-
-       base_uri = soup_uri_new (base_uri_str);
+       base = soup_uri_new (base_uri);
 
-       for (i = 0; i < ntests; i++) {
-               SoupURI *soup_uri = soup_uri_new_with_base (base_uri, current_tests[i].url);
+       for (i = 0; current_tests[i].url; i++) {
+               SoupURI *soup_uri = soup_uri_new_with_base (base, current_tests[i].url);
 
                debug_printf (1, "Test %d: %s\n", i + 1, current_tests[i].explanation);
 
@@ -1269,30 +1199,24 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
                soup_message_add_status_code_handler (
                        msg, "got_headers", SOUP_STATUS_OK,
                        G_CALLBACK (handler), expected);
+
+               signal = g_signal_connect (session, "authenticate",
+                                          G_CALLBACK (authenticate),
+                                          (gpointer)&current_tests[i]);
                soup_session_send_message (session, msg);
-               if (msg->status_code != SOUP_STATUS_UNAUTHORIZED &&
-                   msg->status_code != SOUP_STATUS_OK) {
-                       debug_printf (1, "  %d %s !\n", msg->status_code,
-                                     msg->reason_phrase);
-                       errors++;
-               }
-               if (*expected) {
-                       debug_printf (1, "  expected %d more round(s)\n",
-                                     (int)strlen (expected));
-                       errors++;
-               }
-               g_free (expected);
+               g_signal_handler_disconnect (session, signal);
 
-               if (msg->status_code != current_tests[i].final_status) {
-                       debug_printf (1, "  expected %d\n",
-                                     current_tests[i].final_status);
-               }
+               soup_test_assert_message_status (msg, current_tests[i].final_status);
+               soup_test_assert (!*expected,
+                                 "expected %d more round(s)\n",
+                                 (int)strlen (expected));
 
+               g_free (expected);
                debug_printf (1, "\n");
 
                g_object_unref (msg);
        }
-       soup_uri_free (base_uri);
+       soup_uri_free (base);
 
        soup_test_session_abort_unref (session);
 }
@@ -1300,35 +1224,27 @@ do_batch_tests (const gchar *base_uri_str, gint ntests)
 int
 main (int argc, char **argv)
 {
-       const char *base_uri;
-       int ntests;
+       int ret;
 
        test_init (argc, argv, NULL);
        apache_init ();
 
        base_uri = "http://127.0.0.1:47524/";;
 
-       /* Main tests */
-       current_tests = main_tests;
-       ntests = G_N_ELEMENTS (main_tests);
-       do_batch_tests (base_uri, ntests);
-
-       /* Re-login tests */
-       current_tests = relogin_tests;
-       ntests = G_N_ELEMENTS (relogin_tests);
-       do_batch_tests (base_uri, ntests);
-
-       /* Other regression tests */
-       do_pipelined_auth_test (base_uri);
-       do_digest_expiration_test (base_uri);
-       do_async_auth_test (base_uri);
-       do_select_auth_test ();
-       do_auth_close_test ();
-       do_infinite_auth_test (base_uri);
-       do_disappearing_auth_test ();
+       g_test_add_data_func ("/auth/main-tests", main_tests, do_batch_tests);
+       g_test_add_data_func ("/auth/relogin-tests", relogin_tests, do_batch_tests);
+       g_test_add_func ("/auth/pipelined-auth", do_pipelined_auth_test);
+       g_test_add_func ("/auth/digest-expiration", do_digest_expiration_test);
+       g_test_add_func ("/auth/async-auth", do_async_auth_test);
+       g_test_add_func ("/auth/select-auth", do_select_auth_test);
+       g_test_add_func ("/auth/auth-close", do_auth_close_test);
+       g_test_add_func ("/auth/infinite-auth", do_infinite_auth_test);
+       g_test_add_func ("/auth/disappearing-auth", do_disappearing_auth_test);
+
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_APACHE */
diff --git a/tests/cache-test.c b/tests/cache-test.c
index a19e974..b60fb9c 100644
--- a/tests/cache-test.c
+++ b/tests/cache-test.c
@@ -264,8 +264,9 @@ request_unqueued (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-do_basics_test (SoupURI *base_uri)
+do_basics_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -307,15 +308,9 @@ do_basics_test (SoupURI *base_uri)
        debug_printf (1, "  Fresh cached resource\n");
        cmp = do_request (session, base_uri, "GET", "/1", NULL,
                          NULL);
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /1 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body1, cmp) != 0) {
-               debug_printf (1, "    Cached response (%s) did not match original (%s)\n",
-                             cmp, body1);
-               errors++;
-       }
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /1 not filled from cache");
+       g_assert_cmpstr (body1, ==, cmp);
        g_free (cmp);
 
 
@@ -323,15 +318,9 @@ do_basics_test (SoupURI *base_uri)
        debug_printf (1, "  Heuristically-fresh cached resource\n");
        cmp = do_request (session, base_uri, "GET", "/2", NULL,
                          NULL);
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /2 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body2, cmp) != 0) {
-               debug_printf (1, "    Cached response (%s) did not match original (%s)\n",
-                             cmp, body2);
-               errors++;
-       }
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /2 not filled from cache");
+       g_assert_cmpstr (body2, ==, cmp);
        g_free (cmp);
 
 
@@ -339,23 +328,15 @@ do_basics_test (SoupURI *base_uri)
        debug_printf (1, "  Fresh cached resource with a query\n");
        cmp = do_request (session, base_uri, "GET", "/1?attr=value", NULL,
                          NULL);
-       if (!last_request_hit_network) {
-               debug_printf (1, "    Request for /1?attr=value filled from cache!\n");
-               errors++;
-       }
+       soup_test_assert (last_request_hit_network,
+                         "Request for /1?attr=value filled from cache");
        g_free (cmp);
        debug_printf (2, "  Second request\n");
        cmp = do_request (session, base_uri, "GET", "/1", NULL,
                          NULL);
-       if (last_request_hit_network) {
-               debug_printf (1, "    Second request for /1 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body1, cmp) != 0) {
-               debug_printf (1, "    Cached response (%s) did not match original (%s)\n",
-                             cmp, body1);
-               errors++;
-       }
+       soup_test_assert (!last_request_hit_network,
+                         "Second request for /1 not filled from cache");
+       g_assert_cmpstr (body1, ==, cmp);
        g_free (cmp);
 
 
@@ -365,19 +346,11 @@ do_basics_test (SoupURI *base_uri)
                          "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT",
                          "Test-Set-Cache-Control", "must-revalidate",
                          NULL);
-       if (!last_request_validated) {
-               debug_printf (1, "    Request for /3 not validated!\n");
-               errors++;
-       }
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /3 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body3, cmp) != 0) {
-               debug_printf (1, "    Cached response (%s) did not match original (%s)\n",
-                             cmp, body3);
-               errors++;
-       }
+       soup_test_assert (last_request_validated,
+                         "Request for /3 not validated");
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /3 not filled from cache");
+       g_assert_cmpstr (body3, ==, cmp);
        g_free (cmp);
 
 
@@ -387,18 +360,11 @@ do_basics_test (SoupURI *base_uri)
                          "Test-Set-Last-Modified", "Sat, 02 Jan 2010 00:00:00 GMT",
                          "Test-Set-Cache-Control", "must-revalidate",
                          NULL);
-       if (!last_request_validated) {
-               debug_printf (1, "    Request for /3 not validated!\n");
-               errors++;
-       }
-       if (!last_request_hit_network) {
-               debug_printf (1, "    Request for /3 filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body3, cmp) == 0) {
-               debug_printf (1, "    Request for /3 returned cached response\n");
-               errors++;
-       }
+       soup_test_assert (last_request_validated,
+                         "Request for /3 not validated");
+       soup_test_assert (last_request_hit_network,
+                         "Request for /3 filled from cache");
+       g_assert_cmpstr (body3, !=, cmp);
        g_free (cmp);
 
        debug_printf (2, "  Second request\n");
@@ -406,18 +372,11 @@ do_basics_test (SoupURI *base_uri)
                          "Test-Set-Last-Modified", "Sat, 02 Jan 2010 00:00:00 GMT",
                          "Test-Set-Cache-Control", "must-revalidate",
                          NULL);
-       if (!last_request_validated) {
-               debug_printf (1, "    Second request for /3 not validated!\n");
-               errors++;
-       }
-       if (last_request_hit_network) {
-               debug_printf (1, "    Second request for /3 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body3, cmp) == 0) {
-               debug_printf (1, "    Replacement body for /3 not cached!\n");
-               errors++;
-       }
+       soup_test_assert (last_request_validated,
+                         "Second request for /3 not validated");
+       soup_test_assert (!last_request_hit_network,
+                         "Second request for /3 not filled from cache");
+       g_assert_cmpstr (body3, !=, cmp);
        g_free (cmp);
 
        /* ETag + must-revalidate causes a conditional request */
@@ -425,19 +384,11 @@ do_basics_test (SoupURI *base_uri)
        cmp = do_request (session, base_uri, "GET", "/4", NULL,
                          "Test-Set-ETag", "\"abcdefg\"",
                          NULL);
-       if (!last_request_validated) {
-               debug_printf (1, "    Request for /4 not validated!\n");
-               errors++;
-       }
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /4 not filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body4, cmp) != 0) {
-               debug_printf (1, "    Cached response (%s) did not match original (%s)\n",
-                             cmp, body4);
-               errors++;
-       }
+       soup_test_assert (last_request_validated,
+                         "Request for /4 not validated");
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /4 not filled from cache");
+       g_assert_cmpstr (body4, ==, cmp);
        g_free (cmp);
 
 
@@ -446,15 +397,9 @@ do_basics_test (SoupURI *base_uri)
        cmp = do_request (session, base_uri, "GET", "/5", NULL,
                          "Test-Set-Cache-Control", "no-cache",
                          NULL);
-       if (!last_request_hit_network) {
-               debug_printf (1, "    Request for /5 filled from cache!\n");
-               errors++;
-       }
-       if (strcmp (body5, cmp) != 0) {
-               debug_printf (1, "    Re-retrieved response (%s) did not match original (%s)\n",
-                             cmp, body5);
-               errors++;
-       }
+       soup_test_assert (last_request_hit_network,
+                         "Request for /5 filled from cache");
+       g_assert_cmpstr (body5, ==, cmp);
        g_free (cmp);
 
 
@@ -462,17 +407,14 @@ do_basics_test (SoupURI *base_uri)
        debug_printf (1, "  Invalidating and re-requesting a cached resource\n");
        cmp = do_request (session, base_uri, "PUT", "/1", NULL,
                          NULL);
-       if (!last_request_hit_network) {
-               debug_printf (1, "    PUT filled from cache!\n");
-               errors++;
-       }
+       soup_test_assert (last_request_hit_network,
+                         "PUT filled from cache");
        g_free (cmp);
        cmp = do_request (session, base_uri, "GET", "/1", NULL,
                          NULL);
-       if (!last_request_hit_network) {
-               debug_printf (1, "    PUT failed to invalidate cache entry!\n");
-               errors++;
-       }
+       soup_test_assert (last_request_hit_network,
+                         "PUT failed to invalidate cache entry");
+       g_assert_true (last_request_hit_network);
        g_free (cmp);
 
 
@@ -488,8 +430,9 @@ do_basics_test (SoupURI *base_uri)
 }
 
 static void
-do_cancel_test (SoupURI *base_uri)
+do_cancel_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -521,20 +464,12 @@ do_cancel_test (SoupURI *base_uri)
        debug_printf (1, "  Cancel fresh resource with soup_session_message_cancel()\n");
        flags = SOUP_TEST_REQUEST_CANCEL_MESSAGE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/1", flags);
-       if (cancelled_requests != 1) {
-               debug_printf (1, "    invalid number of cancelled requests: %d (1 expected)\n",
-                             cancelled_requests);
-               errors++;
-       }
+       g_assert_cmpint (cancelled_requests, ==, 1);
 
        debug_printf (1, "  Cancel fresh resource with g_cancellable_cancel()\n");
        flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/1", flags);
-       if (cancelled_requests != 1) {
-               debug_printf (1, "    invalid number of cancelled requests: %d (1 expected)\n",
-                             cancelled_requests);
-               errors++;
-       }
+       g_assert_cmpint (cancelled_requests, ==, 1);
 
        soup_test_session_abort_unref (session);
 
@@ -549,20 +484,12 @@ do_cancel_test (SoupURI *base_uri)
        debug_printf (1, "  Cancel a revalidating resource with soup_session_message_cancel()\n");
        flags = SOUP_TEST_REQUEST_CANCEL_MESSAGE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/2", flags);
-       if (cancelled_requests != 2) {
-               debug_printf (1, "    invalid number of cancelled requests: %d (2 expected)\n",
-                             cancelled_requests);
-               errors++;
-       }
+       g_assert_cmpint (cancelled_requests, ==, 2);
 
        debug_printf (1, "  Cancel a revalidating resource with g_cancellable_cancel()\n");
        flags = SOUP_TEST_REQUEST_CANCEL_CANCELLABLE | SOUP_TEST_REQUEST_CANCEL_IMMEDIATE;
        do_request_with_cancel (session, base_uri, "GET", "/2", flags);
-       if (cancelled_requests != 2) {
-               debug_printf (1, "    invalid number of cancelled requests: %d (2 expected)\n",
-                             cancelled_requests);
-               errors++;
-       }
+       g_assert_cmpint (cancelled_requests, ==, 2);
 
        soup_test_session_abort_unref (session);
 
@@ -586,8 +513,9 @@ base_stream_unreffed (gpointer loop, GObject *ex_base_stream)
 }
 
 static void
-do_refcounting_test (SoupURI *base_uri)
+do_refcounting_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupCache *cache;
        char *cache_dir;
@@ -644,8 +572,9 @@ do_refcounting_test (SoupURI *base_uri)
 }
 
 static void
-do_headers_test (SoupURI *base_uri)
+do_headers_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupMessageHeaders *headers;
        SoupCache *cache;
@@ -678,14 +607,10 @@ do_headers_test (SoupURI *base_uri)
                          "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT",
                          "Test-Set-My-Header", "My header NEW value",
                          NULL);
-       if (!last_request_validated) {
-               debug_printf (1, "    Request for /1 not validated!\n");
-               errors++;
-       }
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /1 not filled from cache!\n");
-               errors++;
-       }
+       soup_test_assert (last_request_validated,
+                         "Request for /1 not validated");
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /1 not filled from cache");
        g_free (cmp);
 
        /* Check that cache returns the updated header */
@@ -694,22 +619,12 @@ do_headers_test (SoupURI *base_uri)
        cmp = do_request (session, base_uri, "GET", "/1", headers,
                          "Test-Set-Last-Modified", "Fri, 01 Jan 2010 00:00:00 GMT",
                          NULL);
-       if (last_request_hit_network) {
-               debug_printf (1, "    Request for /1 not filled from cache!\n");
-               errors++;
-       }
+       soup_test_assert (!last_request_hit_network,
+                         "Request for /1 not filled from cache");
        g_free (cmp);
 
        header_value = soup_message_headers_get_list (headers, "My-Header");
-       if (!header_value) {
-               debug_printf (1, "    Header \"My-Header\" not present!\n");
-               errors++;
-       } else if (strcmp (header_value, "My header NEW value") != 0) {
-               debug_printf (1, "    \"My-Header = %s\" and should be \"%s\"\n",
-                             header_value,
-                             "My header NEW value");
-               errors++;
-       }
+       g_assert_cmpstr (header_value, ==, "My header NEW value");
        soup_message_headers_free (headers);
 
        soup_test_session_abort_unref (session);
@@ -724,6 +639,7 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        SoupURI *base_uri;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -732,14 +648,16 @@ main (int argc, char **argv)
        base_uri = soup_uri_new ("http://127.0.0.1/";);
        soup_uri_set_port (base_uri, soup_server_get_port (server));
 
-       do_basics_test (base_uri);
-       do_cancel_test (base_uri);
-       do_refcounting_test (base_uri);
-       do_headers_test (base_uri);
+       g_test_add_data_func ("/cache/basics", base_uri, do_basics_test);
+       g_test_add_data_func ("/cache/cancellation", base_uri, do_cancel_test);
+       g_test_add_data_func ("/cache/refcounting", base_uri, do_refcounting_test);
+       g_test_add_data_func ("/cache/headers", base_uri, do_headers_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/chunk-io-test.c b/tests/chunk-io-test.c
index f1f96b0..4003e34 100644
--- a/tests/chunk-io-test.c
+++ b/tests/chunk-io-test.c
@@ -350,6 +350,7 @@ do_io_tests (void)
 {
        GInputStream *imem, *islow, *in;
        GOutputStream *omem, *oslow, *out;
+       GMemoryOutputStream *mem;
        char *raw_contents, *buf;
        gsize raw_length;
        GString *chunkified;
@@ -387,35 +388,20 @@ do_io_tests (void)
        while (TRUE) {
                nread = g_input_stream_read (in, buf + total, raw_length - total,
                                             NULL, &error);
-               if (nread == -1) {
-                       debug_printf (1, "  Error reading stream: %s\n", error->message);
-                       g_clear_error (&error);
-                       errors++;
-                       break;
-               } else if (nread == 0)
-                       break;
-               else
+               g_assert_no_error (error);
+               g_clear_error (&error);
+               if (nread > 0)
                        total += nread;
+               else
+                       break;
        }
 
        g_input_stream_close (in, NULL, &error);
-       if (error) {
-               debug_printf (1, "  Error closing input stream: %s\n", error->message);
-               g_clear_error (&error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (in);
 
-       if (total == raw_length) {
-               if (memcmp (buf, raw_contents, raw_length) != 0) {
-                       debug_printf (1, "  mismatch when reading\n");
-                       errors++;
-               }
-       } else {
-               debug_printf (1, "  incorrect read length: %d vs %d\n",
-                             (int) total, (int) raw_length);
-               errors++;
-       }
+       soup_assert_cmpmem (buf, total, raw_contents, raw_length);
        g_free (buf);
 
        debug_printf (1, "  async read\n");
@@ -452,9 +438,8 @@ do_io_tests (void)
                        g_source_unref (source);
                        continue;
                } else if (nread == -1) {
-                       debug_printf (1, "  Error reading stream: %s\n", error->message);
+                       g_assert_no_error (error);
                        g_clear_error (&error);
-                       errors++;
                        break;
                } else if (nread == 0)
                        break;
@@ -463,23 +448,11 @@ do_io_tests (void)
        }
 
        g_input_stream_close (in, NULL, &error);
-       if (error) {
-               debug_printf (1, "  Error closing input stream: %s\n", error->message);
-               g_clear_error (&error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (in);
 
-       if (total == raw_length) {
-               if (memcmp (buf, raw_contents, raw_length) != 0) {
-                       debug_printf (1, "  mismatch when reading\n");
-                       errors++;
-               }
-       } else {
-               debug_printf (1, "  incorrect read length: %d vs %d\n",
-                             (int) total, (int) raw_length);
-               errors++;
-       }
+       soup_assert_cmpmem (buf, total, raw_contents, raw_length);
        g_free (buf);
 
        debug_printf (1, "  sync write\n");
@@ -506,32 +479,25 @@ do_io_tests (void)
                }
                nwrote = g_output_stream_write (out, raw_contents + total,
                                                chunk_length - chunk_total, NULL, &error);
-               if (nwrote == -1) {
-                       debug_printf (1, "  Error writing stream: %s\n", error->message);
-                       g_clear_error (&error);
-                       errors++;
-                       break;
-               } else {
+               g_assert_no_error (error);
+               g_clear_error (&error);
+               if (nwrote > 0) {
                        total += nwrote;
                        chunk_total += nwrote;
-               }
+               } else
+                       break;
        }
 
        g_output_stream_close (out, NULL, &error);
-       if (error) {
-               debug_printf (1, "  Error closing output stream: %s\n", error->message);
-               g_clear_error (&error);
-               errors++;
-       }
-       g_object_unref (out);
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
-       if (total == raw_length) {
-               if (memcmp (buf, chunkified->str, chunkified->len) != 0) {
-                       debug_printf (1, "  mismatch when writing\n");
-                       g_print ("%.*s\n", (int)chunkified->len, buf);
-                       errors++;
-               }
-       }
+       mem = G_MEMORY_OUTPUT_STREAM (omem);
+       soup_assert_cmpmem (g_memory_output_stream_get_data (mem),
+                           g_memory_output_stream_get_data_size (mem),
+                           chunkified->str, chunkified->len);
+
+       g_object_unref (out);
        g_free (buf);
 
        debug_printf (1, "  async write\n");
@@ -573,9 +539,8 @@ do_io_tests (void)
                        g_source_unref (source);
                        continue;
                } else if (nwrote == -1) {
-                       debug_printf (1, "  Error writing stream: %s\n", error->message);
+                       g_assert_no_error (error);
                        g_clear_error (&error);
-                       errors++;
                        break;
                } else {
                        total += nwrote;
@@ -584,19 +549,15 @@ do_io_tests (void)
        }
 
        g_output_stream_close (out, NULL, &error);
-       if (error) {
-               debug_printf (1, "  Error closing output stream: %s\n", error->message);
-               g_clear_error (&error);
-               errors++;
-       }
-       g_object_unref (out);
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
-       if (total == raw_length) {
-               if (memcmp (buf, chunkified->str, chunkified->len) != 0) {
-                       debug_printf (1, "  mismatch when writing\n");
-                       errors++;
-               }
-       }
+       mem = G_MEMORY_OUTPUT_STREAM (omem);
+       soup_assert_cmpmem (g_memory_output_stream_get_data (mem),
+                           g_memory_output_stream_get_data_size (mem),
+                           chunkified->str, chunkified->len);
+
+       g_object_unref (out);
        g_free (buf);
 
        debug_printf (1, "  failed write\n");
@@ -626,10 +587,7 @@ do_io_tests (void)
                        total += nwrote;
        }
 
-       if (total == raw_length) {
-               debug_printf (1, "  breaking stream didn't break?\n");
-               errors++;
-       }
+       g_assert_cmpint (total, !=, raw_length);
 
        g_output_stream_close (out, NULL, NULL);
        g_object_unref (out);
@@ -643,12 +601,16 @@ do_io_tests (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 
        force_io_streams_init ();
 
-       do_io_tests ();
+       g_test_add_func ("/chunk-io", do_io_tests);
+
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/chunk-test.c b/tests/chunk-test.c
index ce92956..de1007d 100644
--- a/tests/chunk-test.c
+++ b/tests/chunk-test.c
@@ -5,6 +5,9 @@
 
 #include "test-utils.h"
 
+static SoupSession *session;
+static SoupURI *base_uri;
+
 typedef struct {
        SoupSession *session;
        SoupBuffer *chunks[3];
@@ -19,9 +22,9 @@ write_next_chunk (SoupMessage *msg, gpointer user_data)
 
        debug_printf (2, "  writing chunk %d\n", ptd->next);
 
-       if (ptd->streaming && ptd->next > 0 && ptd->chunks[ptd->next - 1]) {
-               debug_printf (1, "  error: next chunk requested before last one freed!\n");
-               errors++;
+       if (ptd->streaming && ptd->next > 0) {
+               soup_test_assert (ptd->chunks[ptd->next - 1] == NULL,
+                                 "next chunk requested before last one freed");
        }
 
        if (ptd->next < G_N_ELEMENTS (ptd->chunks)) {
@@ -50,8 +53,8 @@ write_next_chunk_streaming_hack (SoupMessage *msg, gpointer user_data)
                soup_message_body_wrote_chunk (msg->request_body, chunk);
                soup_buffer_free (chunk);
        } else {
-               debug_printf (1, "  error: written chunk does not exist!\n");
-               errors++;
+               soup_test_assert (chunk,
+                                 "written chunk does not exist");
        }
        write_next_chunk (msg, user_data);
 }
@@ -77,8 +80,8 @@ clear_buffer_ptr (gpointer data)
                g_free ((char *)(*buffer_ptr)->data);
                *buffer_ptr = NULL;
        } else {
-               debug_printf (2, "  chunk is already clear!\n");
-               errors++;
+               soup_test_assert (*buffer_ptr,
+                                 "chunk is already clear");
        }
 }
 
@@ -136,8 +139,9 @@ typedef enum {
 } RequestTestFlags;
 
 static void
-do_request_test (SoupSession *session, SoupURI *base_uri, RequestTestFlags flags)
+do_request_test (gconstpointer data)
 {
+       RequestTestFlags flags = GPOINTER_TO_UINT (data);
        SoupURI *uri = base_uri;
        PutTestData ptd;
        SoupMessage *msg;
@@ -199,29 +203,14 @@ do_request_test (SoupSession *session, SoupURI *base_uri, RequestTestFlags flags
                          G_CALLBACK (wrote_body_data), &ptd);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  message failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-
-       if (msg->request_body->data) {
-               debug_printf (1, "  msg->request_body set!\n");
-               errors++;
-       }
-       if (msg->request_body->length != length || length != ptd.nwrote) {
-               debug_printf (1, "  sent length mismatch: %d vs %d vs %d\n",
-                             (int)msg->request_body->length, length, ptd.nwrote);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CREATED);
+       g_assert_null (msg->request_body->data);
+       g_assert_cmpint (msg->request_body->length, ==, length);
+       g_assert_cmpint (length, ==, ptd.nwrote);
 
        server_md5 = soup_message_headers_get_one (msg->response_headers,
                                                   "Content-MD5");
-       if (!server_md5 || strcmp (client_md5, server_md5) != 0) {
-               debug_printf (1, "  client/server data mismatch: %s vs %s\n",
-                             client_md5, server_md5 ? server_md5 : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (client_md5, ==, server_md5);
 
        g_object_unref (msg);
        g_checksum_free (check);
@@ -243,10 +232,8 @@ chunk_allocator (SoupMessage *msg, gsize max_len, gpointer user_data)
 
        debug_printf (2, "  allocating chunk\n");
 
-       if (gtd->current_chunk) {
-               debug_printf (1, "  error: next chunk allocated before last one freed!\n");
-               errors++;
-       }
+       soup_test_assert (gtd->current_chunk == NULL,
+                         "error: next chunk allocated before last one freed");
        gtd->current_chunk = soup_buffer_new_with_owner (g_malloc (6), 6,
                                                         &gtd->current_chunk,
                                                         clear_buffer_ptr);
@@ -270,7 +257,7 @@ got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
 }
 
 static void
-do_response_test (SoupSession *session, SoupURI *base_uri)
+do_response_test (void)
 {
        GetTestData gtd;
        SoupMessage *msg;
@@ -291,30 +278,14 @@ do_response_test (SoupSession *session, SoupURI *base_uri)
                          G_CALLBACK (got_chunk), &gtd);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  message failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-
-       if (msg->response_body->data) {
-               debug_printf (1, "  msg->response_body set!\n");
-               errors++;
-       }
-       if (soup_message_headers_get_content_length (msg->response_headers) != gtd.length) {
-               debug_printf (1, "  received length mismatch: %d vs %d\n",
-                             (int)soup_message_headers_get_content_length (msg->response_headers), 
gtd.length);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       g_assert_null (msg->response_body->data);
+       g_assert_cmpint (soup_message_headers_get_content_length (msg->response_headers), ==, gtd.length);
 
        client_md5 = g_checksum_get_string (gtd.check);
        server_md5 = soup_message_headers_get_one (msg->response_headers,
                                                   "Content-MD5");
-       if (!server_md5 || strcmp (client_md5, server_md5) != 0) {
-               debug_printf (1, "  client/server data mismatch: %s vs %s\n",
-                             client_md5, server_md5 ? server_md5 : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (client_md5, ==, server_md5);
 
        g_object_unref (msg);
        g_checksum_free (gtd.check);
@@ -336,18 +307,18 @@ temp_test_wrote_chunk (SoupMessage *msg, gpointer session)
         * the I/O to stall since soup-message-io will think it's
         * done, but it hasn't written Content-Length bytes yet.
         */
-       if (!chunk) {
-               debug_printf (1, "  Lost second chunk!\n");
-               errors++;
-               soup_session_abort (session);
-       } else
+       if (chunk)
                soup_buffer_free (chunk);
+       else {
+               soup_test_assert (chunk, "Lost second chunk");
+               soup_session_abort (session);
+       }
 
        g_signal_handlers_disconnect_by_func (msg, temp_test_wrote_chunk, session);
 }
 
 static void
-do_temporary_test (SoupSession *session, SoupURI *base_uri)
+do_temporary_test (void)
 {
        SoupMessage *msg;
        char *client_md5;
@@ -368,19 +339,11 @@ do_temporary_test (SoupSession *session, SoupURI *base_uri)
                          G_CALLBACK (temp_test_wrote_chunk), session);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  message failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CREATED);
 
        server_md5 = soup_message_headers_get_one (msg->response_headers,
                                                   "Content-MD5");
-       if (!server_md5 || strcmp (client_md5, server_md5) != 0) {
-               debug_printf (1, "  client/server data mismatch: %s vs %s\n",
-                             client_md5, server_md5 ? server_md5 : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (client_md5, ==, server_md5);
 
        g_free (client_md5);
        g_object_unref (msg);
@@ -398,16 +361,14 @@ large_wrote_body_data (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
 {
        LargeChunkData *lcd = user_data;
 
-       if (memcmp (chunk->data, lcd->buf->data + lcd->offset, chunk->length) != 0) {
-               debug_printf (1, "  chunk data mismatch at %ld\n", (long)lcd->offset);
-               errors++;
-       } else
-               debug_printf (2, "  chunk data match at %ld\n", (long)lcd->offset);
+       soup_assert_cmpmem (chunk->data, chunk->length,
+                           lcd->buf->data + lcd->offset,
+                           chunk->length);
        lcd->offset += chunk->length;
 }
 
 static void
-do_large_chunk_test (SoupSession *session, SoupURI *base_uri)
+do_large_chunk_test (void)
 {
        SoupMessage *msg;
        char *buf_data;
@@ -430,41 +391,13 @@ do_large_chunk_test (SoupSession *session, SoupURI *base_uri)
                          G_CALLBACK (large_wrote_body_data), &lcd);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  message failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CREATED);
 
        soup_buffer_free (lcd.buf);
        g_object_unref (msg);
 }
 
 static void
-do_chunk_tests (SoupURI *base_uri)
-{
-       SoupSession *session;
-
-       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       do_request_test (session, base_uri, 0);
-       debug_printf (2, "\n\n");
-       do_request_test (session, base_uri, PROPER_STREAMING);
-       debug_printf (2, "\n\n");
-       do_request_test (session, base_uri, PROPER_STREAMING | RESTART);
-       debug_printf (2, "\n\n");
-       do_request_test (session, base_uri, HACKY_STREAMING);
-       debug_printf (2, "\n\n");
-       do_request_test (session, base_uri, HACKY_STREAMING | RESTART);
-       debug_printf (2, "\n\n");
-       do_response_test (session, base_uri);
-       debug_printf (2, "\n\n");
-       do_temporary_test (session, base_uri);
-       debug_printf (2, "\n\n");
-       do_large_chunk_test (session, base_uri);
-       soup_test_session_abort_unref (session);
-}
-
-static void
 server_callback (SoupServer *server, SoupMessage *msg,
                 const char *path, GHashTable *query,
                 SoupClientContext *context, gpointer data)
@@ -507,7 +440,7 @@ main (int argc, char **argv)
        GMainLoop *loop;
        SoupServer *server;
        guint port;
-       SoupURI *base_uri;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -520,12 +453,27 @@ main (int argc, char **argv)
 
        base_uri = soup_uri_new ("http://127.0.0.1";);
        soup_uri_set_port (base_uri, port);
-       do_chunk_tests (base_uri);
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+
+       g_test_add_data_func ("/chunks/request/unstreamed", GINT_TO_POINTER (0), do_request_test);
+       g_test_add_data_func ("/chunks/request/proper-streaming", GINT_TO_POINTER (PROPER_STREAMING), 
do_request_test);
+       g_test_add_data_func ("/chunks/request/proper-streaming/restart", GINT_TO_POINTER (PROPER_STREAMING | 
RESTART), do_request_test);
+       g_test_add_data_func ("/chunks/request/hacky-streaming", GINT_TO_POINTER (HACKY_STREAMING), 
do_request_test);
+       g_test_add_data_func ("/chunks/request/hacky-streaming/restart", GINT_TO_POINTER (HACKY_STREAMING | 
RESTART), do_request_test);
+       g_test_add_func ("/chunks/response", do_response_test);
+       g_test_add_func ("/chunks/temporary", do_temporary_test);
+       g_test_add_func ("/chunks/large", do_large_chunk_test);
+
+       ret = g_test_run ();
+
+       soup_test_session_abort_unref (session);
+
        soup_uri_free (base_uri);
 
        g_main_loop_unref (loop);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/coding-test.c b/tests/coding-test.c
index 1bffbc4..8bc3e5f 100644
--- a/tests/coding-test.c
+++ b/tests/coding-test.c
@@ -133,69 +133,20 @@ check_response (SoupMessage *msg,
 {
        const char *coding, *type;
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    Unexpected status %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        coding = soup_message_headers_get_one (msg->response_headers, "Content-Encoding");
-       if (expected_encoding) {
-               if (!coding || g_ascii_strcasecmp (coding, expected_encoding) != 0) {
-                       debug_printf (1, "    Unexpected Content-Encoding: %s\n",
-                                     coding ? coding : "(none)");
-                       errors++;
-               }
-       } else {
-               if (coding) {
-                       debug_printf (1, "    Unexpected Content-Encoding: %s\n",
-                                     coding);
-                       errors++;
-               }
-       }
+       g_assert_cmpstr (coding, ==, expected_encoding);
 
        if (status != NO_CHECK) {
-               if (status == EXPECT_DECODED) {
-                       if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED)) {
-                               debug_printf (1, "    SOUP_MESSAGE_CONTENT_DECODED not set!\n");
-                               errors++;
-                       }
-               } else {
-                       if (soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED) {
-                               debug_printf (1, "    SOUP_MESSAGE_CONTENT_DECODED set!\n");
-                               errors++;
-                       }
-               }
+               if (status == EXPECT_DECODED)
+                       g_assert_true (soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED);
+               else
+                       g_assert_false (soup_message_get_flags (msg) & SOUP_MESSAGE_CONTENT_DECODED);
        }
 
        type = soup_message_headers_get_one (msg->response_headers, "Content-Type");
-       if (!type || g_ascii_strcasecmp (type, expected_content_type) != 0) {
-               debug_printf (1, "    Unexpected Content-Type: %s\n",
-                             type ? type : "(none)");
-               errors++;
-       }
-}
-
-static void
-check_msg_bodies (SoupMessage *msg1,
-                 SoupMessage *msg2,
-                 const char *msg1_type,
-                 const char *msg2_type)
-{
-       if (msg1->response_body->length != msg2->response_body->length) {
-               debug_printf (1, "    Message length mismatch: %lu (%s) vs %lu (%s)\n",
-                             (gulong)msg1->response_body->length,
-                             msg1_type,
-                             (gulong)msg2->response_body->length,
-                             msg2_type);
-               errors++;
-       } else if (memcmp (msg1->response_body->data,
-                          msg2->response_body->data,
-                          msg1->response_body->length) != 0) {
-               debug_printf (1, "    Message data mismatch (%s/%s)\n",
-                             msg1_type, msg2_type);
-               errors++;
-       }
+       g_assert_cmpstr (type, ==, expected_content_type);
 }
 
 static void
@@ -222,7 +173,10 @@ do_coding_test (void)
        msgz = soup_message_new_from_uri ("GET", uri);
        soup_session_send_message (session, msgz);
        check_response (msgz, "gzip", "text/plain", EXPECT_DECODED);
-       check_msg_bodies (msg, msgz, "plain", "compressed");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgz->response_body->data,
+                           msgz->response_body->length);
 
        /* Plain text data, claim gzip w/ junk */
        debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, plus trailing junk\n");
@@ -231,7 +185,10 @@ do_coding_test (void)
                                     "X-Test-Options", "trailing-junk");
        soup_session_send_message (session, msgj);
        check_response (msgj, "gzip", "text/plain", EXPECT_DECODED);
-       check_msg_bodies (msg, msgj, "plain", "compressed w/ junk");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgj->response_body->data,
+                           msgj->response_body->length);
 
        /* Plain text data, claim gzip with server error */
        debug_printf (1, "  GET /mbox, Accept-Encoding: gzip, with server error\n");
@@ -245,7 +202,10 @@ do_coding_test (void)
         * from what the server sent... which happens to be the
         * uncompressed data.
         */
-       check_msg_bodies (msg, msge, "plain", "mis-encoded");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msge->response_body->data,
+                           msge->response_body->length);
 
        /* Plain text data, claim deflate */
        debug_printf (1, "  GET /mbox, Accept-Encoding: deflate\n");
@@ -254,7 +214,10 @@ do_coding_test (void)
                                     "X-Test-Options", "prefer-deflate-zlib");
        soup_session_send_message (session, msgzl);
        check_response (msgzl, "deflate", "text/plain", EXPECT_DECODED);
-       check_msg_bodies (msg, msgzl, "plain", "compressed");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgzl->response_body->data,
+                           msgzl->response_body->length);
 
        /* Plain text data, claim deflate w/ junk */
        debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, plus trailing junk\n");
@@ -263,7 +226,10 @@ do_coding_test (void)
                                     "X-Test-Options", "prefer-deflate-zlib, trailing-junk");
        soup_session_send_message (session, msgzlj);
        check_response (msgzlj, "deflate", "text/plain", EXPECT_DECODED);
-       check_msg_bodies (msg, msgzlj, "plain", "compressed w/ junk");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgzlj->response_body->data,
+                           msgzlj->response_body->length);
 
        /* Plain text data, claim deflate with server error */
        debug_printf (1, "  GET /mbox, Accept-Encoding: deflate, with server error\n");
@@ -272,7 +238,10 @@ do_coding_test (void)
                                     "X-Test-Options", "force-encode, prefer-deflate-zlib");
        soup_session_send_message (session, msgzle);
        check_response (msgzle, "deflate", "text/plain", EXPECT_NOT_DECODED);
-       check_msg_bodies (msg, msgzle, "plain", "mis-encoded");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgzle->response_body->data,
+                           msgzle->response_body->length);
 
        /* Plain text data, claim deflate (no zlib headers)*/
        debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data)\n");
@@ -281,7 +250,10 @@ do_coding_test (void)
                                     "X-Test-Options", "prefer-deflate-raw");
        soup_session_send_message (session, msgzlr);
        check_response (msgzlr, "deflate", "text/plain", EXPECT_DECODED);
-       check_msg_bodies (msg, msgzlr, "plain", "compressed");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgzlr->response_body->data,
+                           msgzlr->response_body->length);
 
        /* Plain text data, claim deflate with server error */
        debug_printf (1, "  GET /mbox, Accept-Encoding: deflate (raw data), with server error\n");
@@ -290,7 +262,10 @@ do_coding_test (void)
                                     "X-Test-Options", "force-encode, prefer-deflate-raw");
        soup_session_send_message (session, msgzlre);
        check_response (msgzlre, "deflate", "text/plain", EXPECT_NOT_DECODED);
-       check_msg_bodies (msg, msgzlre, "plain", "mis-encoded");
+       soup_assert_cmpmem (msg->response_body->data,
+                           msg->response_body->length,
+                           msgzlre->response_body->data,
+                           msgzlre->response_body->length);
 
        g_object_unref (msg);
        g_object_unref (msgzlre);
@@ -314,12 +289,8 @@ read_finished (GObject *stream, GAsyncResult *result, gpointer user_data)
 
        *nread = g_input_stream_read_finish (G_INPUT_STREAM (stream),
                                             result, &error);
-       if (error) {
-               debug_printf (1, "    Error reading: %s\n",
-                             error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
 }
 
 static GByteArray *
@@ -338,11 +309,9 @@ do_single_coding_req_test (SoupRequestHTTP *reqh,
        data = g_byte_array_new ();
 
        stream = soup_test_request_send (SOUP_REQUEST (reqh), NULL, 0, &error);
-       if (error) {
-               debug_printf (1, "    Error sending request: %s\n",
-                             error->message);
+       if (!stream) {
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                return data;
        }
 
@@ -359,12 +328,8 @@ do_single_coding_req_test (SoupRequestHTTP *reqh,
        } while (nread > 0);
 
        soup_test_request_close_stream (SOUP_REQUEST (reqh), stream, NULL, &error);
-       if (error) {
-               debug_printf (1, "    error closing stream: %s\n",
-                             error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (stream);
 
        msg = soup_request_http_get_message (reqh);
@@ -375,24 +340,6 @@ do_single_coding_req_test (SoupRequestHTTP *reqh,
 }
 
 static void
-check_req_bodies (GByteArray *body1,
-                 GByteArray *body2,
-                 const char *msg1_type,
-                 const char *msg2_type)
-{
-       if (body1->len != body2->len) {
-               debug_printf (1, "    Message length mismatch: %lu (%s) vs %lu (%s)\n",
-                             (gulong)body1->len, msg1_type,
-                             (gulong)body2->len, msg2_type);
-               errors++;
-       } else if (memcmp (body1->data, body2->data, body1->len) != 0) {
-               debug_printf (1, "    Message data mismatch (%s/%s)\n",
-                             msg1_type, msg2_type);
-               errors++;
-       }
-}
-
-static void
 do_coding_req_test (void)
 {
        SoupSession *session;
@@ -419,7 +366,8 @@ do_coding_req_test (void)
        soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_DECODER);
        reqh = soup_session_request_http_uri (session, "GET", uri, NULL);
        cmp = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "compressed");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -431,7 +379,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "trailing-junk");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "gzip", "text/plain", EXPECT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -448,7 +397,8 @@ do_coding_req_test (void)
         * from what the server sent... which happens to be the
         * uncompressed data.
         */
-       check_req_bodies (plain, cmp, "plain", "mis-encoded");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -460,7 +410,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "prefer-deflate-zlib");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "compressed");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -472,7 +423,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "prefer-deflate-zlib, trailing-junk");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "compressed w/ junk");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -484,7 +436,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "force-encode, prefer-deflate-zlib");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_NOT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "mis-encoded");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -496,7 +449,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "prefer-deflate-raw");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "compressed");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -508,7 +462,8 @@ do_coding_req_test (void)
                                     "X-Test-Options", "force-encode, prefer-deflate-raw");
        g_object_unref (msg);
        cmp = do_single_coding_req_test (reqh, "deflate", "text/plain", EXPECT_NOT_DECODED);
-       check_req_bodies (plain, cmp, "plain", "mis-encoded");
+       soup_assert_cmpmem (plain->data, plain->len,
+                           cmp->data, cmp->len);
        g_byte_array_free (cmp, TRUE);
        g_object_unref (reqh);
 
@@ -561,6 +516,8 @@ do_coding_empty_test (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 
        server = soup_test_server_new (TRUE);
@@ -568,13 +525,15 @@ main (int argc, char **argv)
        base_uri = soup_uri_new ("http://127.0.0.1/";);
        soup_uri_set_port (base_uri, soup_server_get_port (server));
 
-       do_coding_test ();
-       do_coding_req_test ();
-       do_coding_empty_test ();
+       g_test_add_func ("/coding/message", do_coding_test);
+       g_test_add_func ("/coding/request", do_coding_req_test);
+       g_test_add_func ("/coding/empty", do_coding_empty_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/connection-test.c b/tests/connection-test.c
index fd7179f..3dd2cae 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -174,21 +174,14 @@ do_content_length_framing_test (void)
        request_uri = soup_uri_new_with_base (base_uri, "/content-length/long");
        msg = soup_message_new_from_uri ("GET", request_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       } else {
-               declared_length = soup_message_headers_get_content_length (msg->response_headers);
-               debug_printf (2, "    Content-Length: %lu, body: %s\n",
-                             (gulong)declared_length, msg->response_body->data);
-               if (msg->response_body->length >= declared_length) {
-                       debug_printf (1, "    Body length %lu >= declared length %lu\n",
-                                     (gulong)msg->response_body->length,
-                                     (gulong)declared_length);
-                       errors++;
-               }
-       }
+
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
+       declared_length = soup_message_headers_get_content_length (msg->response_headers);
+       debug_printf (2, "    Content-Length: %lu, body: %s\n",
+                     (gulong)declared_length, msg->response_body->data);
+       g_assert_cmpint (msg->response_body->length, <, declared_length);
+
        soup_uri_free (request_uri);
        g_object_unref (msg);
 
@@ -196,21 +189,12 @@ do_content_length_framing_test (void)
        request_uri = soup_uri_new_with_base (base_uri, "/content-length/noclose");
        msg = soup_message_new_from_uri ("GET", request_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       } else {
-               declared_length = soup_message_headers_get_content_length (msg->response_headers);
-               debug_printf (2, "    Content-Length: %lu, body: %s\n",
-                             (gulong)declared_length, msg->response_body->data);
-               if (msg->response_body->length != declared_length) {
-                       debug_printf (1, "    Body length %lu != declared length %lu\n",
-                                     (gulong)msg->response_body->length,
-                                     (gulong)declared_length);
-                       errors++;
-               }
-       }
+
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
+       declared_length = soup_message_headers_get_content_length (msg->response_headers);
+       g_assert_cmpint (msg->response_body->length, ==, declared_length);
+
        soup_uri_free (request_uri);
        g_object_unref (msg);
 
@@ -234,12 +218,11 @@ request_started_socket_collector (SoupSession *session, SoupMessage *msg,
                         * two consecutive sockets.
                         */
                        sockets[i] = g_object_ref (socket);
-                       return;
+                       break;
                }
        }
 
-       debug_printf (1, "      socket queue overflowed!\n");
-       errors++;
+       soup_test_assert (i < 4, "socket queue overflowed");
 }
 
 static void
@@ -259,14 +242,10 @@ do_timeout_test_for_session (SoupSession *session)
        msg = soup_message_new_from_uri ("GET", timeout_uri);
        soup_uri_free (timeout_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
        if (sockets[1]) {
-               debug_printf (1, "      Message was retried??\n");
-               errors++;
+               soup_test_assert (sockets[1] == NULL, "Message was retried");
                sockets[1] = sockets[2] = sockets[3] = NULL;
        }
        g_object_unref (msg);
@@ -274,24 +253,16 @@ do_timeout_test_for_session (SoupSession *session)
        debug_printf (1, "    Second message\n");
        msg = soup_message_new_from_uri ("GET", base_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-       if (sockets[1] != sockets[0]) {
-               debug_printf (1, "      Message was not retried on existing connection\n");
-               errors++;
-       } else if (!sockets[2]) {
-               debug_printf (1, "      Message was not retried after disconnect\n");
-               errors++;
-       } else if (sockets[2] == sockets[1]) {
-               debug_printf (1, "      Message was retried on closed connection??\n");
-               errors++;
-       } else if (sockets[3]) {
-               debug_printf (1, "      Message was retried again??\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
+       soup_test_assert (sockets[1] == sockets[0],
+                         "Message was not retried on existing connection");
+       soup_test_assert (sockets[2] != NULL,
+                         "Message was not retried after disconnect");
+       soup_test_assert (sockets[2] != sockets[1],
+                         "Message was retried on closed connection");
+       soup_test_assert (sockets[3] == NULL,
+                         "Message was retried again");
        g_object_unref (msg);
 
        for (i = 0; sockets[i]; i++)
@@ -319,33 +290,26 @@ do_timeout_req_test_for_session (SoupSession *session)
        soup_uri_free (timeout_uri);
 
        stream = soup_test_request_send (req, NULL, 0, &error);
-       if (!stream) {
-               debug_printf (1, "      Unexpected error on send: %s\n",
-                             error->message);
-               errors++;
+       if (error) {
+               g_assert_no_error (error);
                g_clear_error (&error);
        } else {
                soup_test_request_read_all (req, stream, NULL, &error);
                if (error) {
-                       debug_printf (1, "  Unexpected error on read: %s\n",
-                                     error->message);
-                       errors++;
+                       g_assert_no_error (error);
                        g_clear_error (&error);
                }
 
                soup_test_request_close_stream (req, stream, NULL, &error);
                if (error) {
-                       debug_printf (1, "  Unexpected error on close: %s\n",
-                                     error->message);
-                       errors++;
+                       g_assert_no_error (error);
                        g_clear_error (&error);
                }
                g_object_unref (stream);
        }
 
        if (sockets[1]) {
-               debug_printf (1, "      Message was retried??\n");
-               errors++;
+               soup_test_assert (sockets[1] == NULL, "Message was retried");
                sockets[1] = sockets[2] = sockets[3] = NULL;
        }
        g_object_unref (req);
@@ -354,41 +318,29 @@ do_timeout_req_test_for_session (SoupSession *session)
        req = soup_session_request_uri (session, base_uri, NULL);
 
        stream = soup_test_request_send (req, NULL, 0, &error);
-       if (!stream) {
-               debug_printf (1, "      Unexpected error on send: %s\n",
-                             error->message);
-               errors++;
+       if (error) {
+               g_assert_no_error (error);
                g_clear_error (&error);
        } else {
                soup_test_request_close_stream (req, stream, NULL, &error);
                if (error) {
-                       debug_printf (1, "  Unexpected error on close: %s\n",
-                                     error->message);
-                       errors++;
+                       g_assert_no_error (error);
                        g_clear_error (&error);
                }
                g_object_unref (stream);
        }
 
        msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (req));
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-       if (sockets[1] != sockets[0]) {
-               debug_printf (1, "      Message was not retried on existing connection\n");
-               errors++;
-       } else if (!sockets[2]) {
-               debug_printf (1, "      Message was not retried after disconnect\n");
-               errors++;
-       } else if (sockets[2] == sockets[1]) {
-               debug_printf (1, "      Message was retried on closed connection??\n");
-               errors++;
-       } else if (sockets[3]) {
-               debug_printf (1, "      Message was retried again??\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
+       soup_test_assert (sockets[1] == sockets[0],
+                         "Message was not retried on existing connection");
+       soup_test_assert (sockets[2] != NULL,
+                         "Message was not retried after disconnect");
+       soup_test_assert (sockets[2] != sockets[1],
+                         "Message was retried on closed connection");
+       soup_test_assert (sockets[3] == NULL,
+                         "Message was retried again");
        g_object_unref (msg);
        g_object_unref (req);
 
@@ -486,11 +438,7 @@ do_max_conns_test_for_session (SoupSession *session)
        }
 
        g_main_loop_run (max_conns_loop);
-       if (msgs_done != MAX_CONNS) {
-               debug_printf (1, "  Queued %d connections out of max %d?",
-                             msgs_done, MAX_CONNS);
-               errors++;
-       }
+       g_assert_cmpint (msgs_done, ==, MAX_CONNS);
        g_signal_handlers_disconnect_by_func (session, max_conns_request_started, NULL);
 
        msgs_done = 0;
@@ -500,14 +448,8 @@ do_max_conns_test_for_session (SoupSession *session)
        quit_loop_timeout = g_timeout_add (1000, quit_loop, NULL);
        g_main_loop_run (max_conns_loop);
 
-       for (i = 0; i < TEST_CONNS; i++) {
-               if (!SOUP_STATUS_IS_SUCCESSFUL (msgs[i]->status_code)) {
-                       debug_printf (1, "    Message %d failed? %d %s\n",
-                                     i, msgs[i]->status_code,
-                                     msgs[i]->reason_phrase ? msgs[i]->reason_phrase : "-");
-                       errors++;
-               }
-       }
+       for (i = 0; i < TEST_CONNS; i++)
+               soup_test_assert_message_status (msgs[i], SOUP_STATUS_OK);
 
        if (msgs_done != TEST_CONNS) {
                /* Clean up so we don't get a spurious "Leaked
@@ -565,10 +507,7 @@ np_request_unqueued (SoupSession *session, SoupMessage *msg,
 {
        SoupSocket *socket = *(SoupSocket **)user_data;
 
-       if (soup_socket_is_connected (socket)) {
-               debug_printf (1, "    socket is still connected\n");
-               errors++;
-       }
+       g_assert_false (soup_socket_is_connected (socket));
 }
 
 static void
@@ -604,11 +543,8 @@ do_non_persistent_test_for_session (SoupSession *session)
        g_main_loop_run (loop);
        g_main_loop_unref (loop);
 
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
        g_object_unref (msg);
        g_object_unref (socket);
 }
@@ -645,14 +581,9 @@ do_non_idempotent_test_for_session (SoupSession *session)
        debug_printf (2, "    GET\n");
        msg = soup_message_new_from_uri ("GET", base_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        if (sockets[1]) {
-               debug_printf (1, "      Message was retried??\n");
-               errors++;
+               soup_test_assert (sockets[1] == NULL, "Message was retried");
                sockets[1] = sockets[2] = sockets[3] = NULL;
        }
        g_object_unref (msg);
@@ -660,19 +591,12 @@ do_non_idempotent_test_for_session (SoupSession *session)
        debug_printf (2, "    POST\n");
        msg = soup_message_new_from_uri ("POST", base_uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-       if (sockets[1] == sockets[0]) {
-               debug_printf (1, "      Message was sent on existing connection!\n");
-               errors++;
-       }
-       if (sockets[2]) {
-               debug_printf (1, "      Too many connections used...\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       soup_test_assert (sockets[1] != sockets[0],
+                         "Message was sent on existing connection");
+       soup_test_assert (sockets[2] == NULL,
+                         "Too many connections used");
+
        g_object_unref (msg);
 
        for (i = 0; sockets[i]; i++)
@@ -726,15 +650,11 @@ connection_state_changed (GObject *object, GParamSpec *param,
        SoupConnectionState new_state;
 
        g_object_get (object, "state", &new_state, NULL);
-       if (state_transitions[*state] != new_state) {
-               debug_printf (1, "      Unexpected transition: %s -> %s\n",
-                             state_names[*state], state_names[new_state]);
-               errors++;
-       } else {
-               debug_printf (2, "      %s -> %s\n",
-                             state_names[*state], state_names[new_state]);
-       }
-
+       debug_printf (2, "      %s -> %s\n",
+                     state_names[*state], state_names[new_state]);
+       soup_test_assert (state_transitions[*state] == new_state,
+                         "Unexpected transition: %s -> %s\n",
+                         state_names[*state], state_names[new_state]);
        *state = new_state;
 }
 
@@ -745,11 +665,7 @@ connection_created (SoupSession *session, GObject *conn,
        SoupConnectionState *state = user_data;
 
        g_object_get (conn, "state", state, NULL);
-       if (*state != SOUP_CONNECTION_NEW) {
-               debug_printf (1, "      Unexpected initial state: %d\n",
-                             *state);
-               errors++;
-       }
+       g_assert_cmpint (*state, ==, SOUP_CONNECTION_NEW);
 
        g_signal_connect (conn, "notify::state",
                          G_CALLBACK (connection_state_changed),
@@ -763,11 +679,7 @@ do_one_connection_state_test (SoupSession *session, const char *uri)
 
        msg = soup_message_new ("GET", uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
        soup_session_abort (session);
 }
@@ -854,21 +766,12 @@ network_event (SoupMessage *msg, GSocketClientEvent event,
 {
        const char **events = user_data;
 
-       if (!**events) {
-               debug_printf (1, "      Unexpected event: %s\n",
-                             event_names[event]);
-               errors++;
-       } else {
-               if (**events == event_abbrevs[event])
-                       debug_printf (2, "      %s\n", event_names[event]);
-               else {
-                       debug_printf (1, "      Unexpected event: %s (expected %s)\n",
-                                     event_names[event],
-                                     event_name_from_abbrev (**events));
-                       errors++;
-               }
-               *events = *events + 1;
-       }
+       debug_printf (2, "      %s\n", event_name_from_abbrev (**events));
+       soup_test_assert (**events == event_abbrevs[event],
+                         "Unexpected event: %s (expected %s)\n",
+                         event_names[event],
+                         event_name_from_abbrev (**events));
+       *events = *events + 1;
 }
 
 static void
@@ -882,18 +785,14 @@ do_one_connection_event_test (SoupSession *session, const char *uri,
                          G_CALLBACK (network_event),
                          &events);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "      Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       } else {
-               while (*events) {
-                       debug_printf (1, "      Expected %s\n",
-                                     event_name_from_abbrev (*events));
-                       events++;
-                       errors++;
-               }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       while (*events) {
+               soup_test_assert (!*events,
+                                 "Expected %s",
+                                 event_name_from_abbrev (*events));
+               events++;
        }
+
        g_object_unref (msg);
        soup_session_abort (session);
 }
@@ -951,6 +850,8 @@ do_connection_event_test (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 #ifdef HAVE_APACHE
        apache_init ();
@@ -961,19 +862,21 @@ main (int argc, char **argv)
        base_uri = soup_uri_new ("http://127.0.0.1/";);
        soup_uri_set_port (base_uri, soup_server_get_port (server));
 
-       do_content_length_framing_test ();
-       do_persistent_connection_timeout_test ();
-       do_max_conns_test ();
-       do_non_persistent_connection_test ();
-       do_non_idempotent_connection_test ();
+       g_test_add_func ("/connection/content-length-framing", do_content_length_framing_test);
+       g_test_add_func ("/connection/persistent-connection-timeout", do_persistent_connection_timeout_test);
+       g_test_add_func ("/connection/max-conns", do_max_conns_test);
+       g_test_add_func ("/connection/non-persistent", do_non_persistent_connection_test);
+       g_test_add_func ("/connection/non-idempotent", do_non_idempotent_connection_test);
 #ifdef HAVE_APACHE
-       do_connection_state_test ();
-       do_connection_event_test ();
+       g_test_add_func ("/connection/state", do_connection_state_test);
+       g_test_add_func ("/connection/event", do_connection_event_test);
 #endif
 
+       ret = g_test_run ();
+
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/context-test.c b/tests/context-test.c
index 97cd2c0..7fe3d60 100644
--- a/tests/context-test.c
+++ b/tests/context-test.c
@@ -84,9 +84,11 @@ static GMutex test1_mutex;
 static GMainLoop *test1_loop;
 
 static void
-do_test1 (int n, gboolean use_thread_context)
+do_test1 (gconstpointer data)
 {
-       debug_printf (1, "\nTest %d: blocking the main thread does not block other thread\n", n);
+       gboolean use_thread_context = GPOINTER_TO_INT (data);
+
+       debug_printf (1, "\nBlocking the main thread does not block other thread\n");
        if (use_thread_context)
                debug_printf (1, "(Using g_main_context_push_thread_default())\n");
        else
@@ -111,9 +113,8 @@ idle_start_test1_thread (gpointer use_thread_context)
        if (g_cond_wait_until (&test1_cond, &test1_mutex, time))
                g_thread_join (thread);
        else {
-               debug_printf (1, "  timeout!\n");
+               soup_test_assert (FALSE, "timeout");
                g_thread_unref (thread);
-               errors++;
        }
 
        g_mutex_unlock (&test1_mutex);
@@ -158,11 +159,7 @@ test1_thread (gpointer use_thread_context)
        debug_printf (1, "  send_message\n");
        msg = soup_message_new ("GET", uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
 
        debug_printf (1, "  queue_message\n");
@@ -172,11 +169,7 @@ test1_thread (gpointer use_thread_context)
        soup_session_queue_message (session, msg, test1_finished, loop);
        g_main_loop_run (loop);
        g_main_loop_unref (loop);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -196,15 +189,16 @@ test1_thread (gpointer use_thread_context)
 static gboolean idle_test2_fail (gpointer user_data);
 
 static void
-do_test2 (int n, gboolean use_thread_context)
+do_test2 (gconstpointer data)
 {
+       gboolean use_thread_context = GPOINTER_TO_INT (data);
        guint idle;
        GMainContext *async_context;
        SoupSession *session;
        char *uri;
        SoupMessage *msg;
 
-       debug_printf (1, "\nTest %d: a session with its own context is independent of the main loop.\n", n);
+       debug_printf (1, "\nA session with its own context is independent of the main loop.\n");
        if (use_thread_context)
                debug_printf (1, "(Using g_main_context_push_thread_default())\n");
        else
@@ -230,11 +224,7 @@ do_test2 (int n, gboolean use_thread_context)
        debug_printf (1, "  send_message\n");
        msg = soup_message_new ("GET", uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -249,8 +239,7 @@ do_test2 (int n, gboolean use_thread_context)
 static gboolean
 idle_test2_fail (gpointer user_data)
 {
-       debug_printf (1, "  idle ran!\n");
-       errors++;
+       soup_test_assert (FALSE, "idle ran");
        return FALSE;
 }
 
@@ -279,14 +268,14 @@ multi_msg_finished (SoupSession *session, SoupMessage *msg, gpointer user_data)
 }
 
 static void
-do_multicontext_test (int n)
+do_multicontext_test (void)
 {
        SoupSession *session;
        SoupMessage *msg1, *msg2;
        GMainContext *context1, *context2;
        GMainLoop *loop1, *loop2;
 
-       debug_printf (1, "\nTest %d: Using multiple async contexts\n", n);
+       debug_printf (1, "\nUsing multiple async contexts\n");
 
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
@@ -318,36 +307,26 @@ do_multicontext_test (int n)
        g_main_loop_run (loop1);
        g_main_context_pop_thread_default (context1);
 
-       if (!g_object_get_data (G_OBJECT (msg1), "started")) {
-               debug_printf (1, "  msg1 not started??\n");
-               errors++;
-       }
-       if (g_object_get_data (G_OBJECT (msg2), "started")) {
-               debug_printf (1, "  msg2 started while loop1 was running!\n");
-               errors++;
-       }
+       if (!g_object_get_data (G_OBJECT (msg1), "started"))
+               soup_test_assert (FALSE, "msg1 not started");
+       if (g_object_get_data (G_OBJECT (msg2), "started"))
+               soup_test_assert (FALSE, "msg2 started while loop1 was running");
 
        g_main_context_push_thread_default (context2);
        g_main_loop_run (loop2);
        g_main_context_pop_thread_default (context2);
 
-       if (g_object_get_data (G_OBJECT (msg1), "finished")) {
-               debug_printf (1, "  msg1 finished while loop2 was running!\n");
-               errors++;
-       }
-       if (!g_object_get_data (G_OBJECT (msg2), "finished")) {
-               debug_printf (1, "  msg2 not finished??\n");
-               errors++;
-       }
+       if (g_object_get_data (G_OBJECT (msg1), "finished"))
+               soup_test_assert (FALSE, "msg1 finished while loop2 was running");
+       if (!g_object_get_data (G_OBJECT (msg2), "finished"))
+               soup_test_assert (FALSE, "msg2 not finished");
 
        g_main_context_push_thread_default (context1);
        g_main_loop_run (loop1);
        g_main_context_pop_thread_default (context1);
 
-       if (!g_object_get_data (G_OBJECT (msg1), "finished")) {
-               debug_printf (1, "  msg1 not finished??\n");
-               errors++;
-       }
+       if (!g_object_get_data (G_OBJECT (msg1), "finished"))
+               soup_test_assert (FALSE, "msg1 not finished");
 
        g_object_unref (msg1);
        g_object_unref (msg2);
@@ -364,6 +343,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -372,15 +352,17 @@ main (int argc, char **argv)
        base_uri = g_strdup_printf ("http://127.0.0.1:%u/";,
                                    soup_server_get_port (server));
 
-       do_test1 (1, FALSE);
-       do_test1 (2, TRUE);
-       do_test2 (3, FALSE);
-       do_test2 (4, TRUE);
-       do_multicontext_test (5);
+       g_test_add_data_func ("/context/blocking/explicit", GINT_TO_POINTER (FALSE), do_test1);
+       g_test_add_data_func ("/context/blocking/thread-default", GINT_TO_POINTER (TRUE), do_test1);
+       g_test_add_data_func ("/context/nested/explicit", GINT_TO_POINTER (FALSE), do_test2);
+       g_test_add_data_func ("/context/nested/thread-default", GINT_TO_POINTER (TRUE), do_test2);
+       g_test_add_func ("/context/multiple", do_multicontext_test);
+
+       ret = g_test_run ();
 
        g_free (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/continue-test.c b/tests/continue-test.c
index 7cc9f69..42138ce 100644
--- a/tests/continue-test.c
+++ b/tests/continue-test.c
@@ -106,17 +106,13 @@ do_message (const char *path, gboolean long_body,
        while ((expected_event = va_arg (ap, const char *))) {
 
                if (!events) {
-                       debug_printf (1, "  Expected '%s', got end of list\n",
-                                     expected_event);
-                       errors++;
+                       soup_test_assert (events != NULL,
+                                         "Expected '%s', got end of list",
+                                         expected_event);
                        continue;
                } else {
                        actual_event = events->data;
-                       if (strcmp (expected_event, actual_event) != 0) {
-                               debug_printf (1, "  Expected '%s', got '%s'\n",
-                                             expected_event, actual_event);
-                               errors++;
-                       }
+                       g_assert_cmpstr (expected_event, ==, actual_event);
                        events = g_slist_delete_link (events, events);
                }
 
@@ -134,10 +130,10 @@ do_message (const char *path, gboolean long_body,
 
                if (expected_status != -1 && actual_status != -1 &&
                    expected_status != actual_status) {
-                       debug_printf (1, "  Expected status '%s', got '%s'\n",
-                                     soup_status_get_phrase (expected_status),
-                                     soup_status_get_phrase (actual_status));
-                       errors++;
+                       soup_test_assert (expected_status == actual_status,
+                                         "Expected status '%s', got '%s'",
+                                         soup_status_get_phrase (expected_status),
+                                         soup_status_get_phrase (actual_status));
                }
 
                g_free (actual_event);
@@ -145,8 +141,8 @@ do_message (const char *path, gboolean long_body,
        va_end (ap);
        while (events) {
                actual_event = events->data;
-               debug_printf (1, "  Expected to be done, got '%s'\n", actual_event);
-               errors++;
+               soup_test_assert (events == NULL,
+                                 "Expected to be done, got '%s'", actual_event);
                events = g_slist_delete_link (events, events);
 
                if (!strcmp (actual_event, "server-wrote_headers") ||
@@ -434,15 +430,19 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
+       int ret;
 
        test_init (argc, argv, NULL);
 
        server = setup_server ();
        port = soup_server_get_port (server);
 
-       run_tests ();
+       g_test_add_func ("/continue", run_tests);
+
+       ret = g_test_run ();
 
        soup_test_server_quit_unref (server);
        test_cleanup ();
-       return errors != 0;
+
+       return ret;
 }
diff --git a/tests/cookies-test.c b/tests/cookies-test.c
index 58f8052..b36b14a 100644
--- a/tests/cookies-test.c
+++ b/tests/cookies-test.c
@@ -83,13 +83,7 @@ do_cookies_accept_policy_test (void)
                g_object_unref (msg);
 
                l = soup_cookie_jar_all_cookies (jar);
-               if (g_slist_length (l) < validResults[i].n_cookies) {
-                       debug_printf (1, " accepted less cookies than it should have\n");
-                       errors++;
-               } else if (g_slist_length (l) > validResults[i].n_cookies) {
-                       debug_printf (1, " accepted more cookies than it should have\n");
-                       errors++;
-               }
+               g_assert_cmpint (g_slist_length (l), ==, validResults[i].n_cookies);
 
                for (p = l; p; p = p->next) {
                        soup_cookie_jar_delete_cookie (jar, p->data);
@@ -146,56 +140,28 @@ do_cookies_parsing_test (void)
 
                if (!strcmp (soup_cookie_get_name (cookie), "one")) {
                        got1 = TRUE;
-                       if (!soup_cookie_get_http_only (cookie)) {
-                               debug_printf (1, "  cookie 1 is not HttpOnly!\n");
-                               errors++;
-                       }
-                       if (!soup_cookie_get_expires (cookie)) {
-                               debug_printf (1, "  cookie 1 did not fully parse!\n");
-                               errors++;
-                       }
+                       g_assert_true (soup_cookie_get_http_only (cookie));
+                       g_assert_true (soup_cookie_get_expires (cookie) != NULL);
                } else if (!strcmp (soup_cookie_get_name (cookie), "two")) {
                        got2 = TRUE;
-                       if (!soup_cookie_get_http_only (cookie)) {
-                               debug_printf (1, "  cookie 2 is not HttpOnly!\n");
-                               errors++;
-                       }
-                       if (!soup_cookie_get_expires (cookie)) {
-                               debug_printf (1, "  cookie 3 did not fully parse!\n");
-                               errors++;
-                       }
+                       g_assert_true (soup_cookie_get_http_only (cookie));
+                       g_assert_true (soup_cookie_get_expires (cookie) != NULL);
                } else if (!strcmp (soup_cookie_get_name (cookie), "three")) {
                        got3 = TRUE;
-                       if (!soup_cookie_get_http_only (cookie)) {
-                               debug_printf (1, "  cookie 3 is not HttpOnly!\n");
-                               errors++;
-                       }
-                       if (!soup_cookie_get_expires (cookie)) {
-                               debug_printf (1, "  cookie 3 did not fully parse!\n");
-                               errors++;
-                       }
+                       g_assert_true (soup_cookie_get_http_only (cookie));
+                       g_assert_true (soup_cookie_get_expires (cookie) != NULL);
                } else {
-                       debug_printf (1, "  got unexpected cookie '%s'\n",
-                                     soup_cookie_get_name (cookie));
-                       errors++;
+                       soup_test_assert (FALSE, "got unexpected cookie '%s'",
+                                         soup_cookie_get_name (cookie));
                }
 
                soup_cookie_free (cookie);
        }
        g_slist_free (cookies);
 
-       if (!got1) {
-               debug_printf (1, "  didn't get cookie 1\n");
-               errors++;
-       }
-       if (!got2) {
-               debug_printf (1, "  didn't get cookie 2\n");
-               errors++;
-       }
-       if (!got3) {
-               debug_printf (1, "  didn't get cookie 3\n");
-               errors++;
-       }
+       g_assert_true (got1);
+       g_assert_true (got2);
+       g_assert_true (got3);
 
        soup_test_session_abort_unref (session);
 }      
@@ -203,6 +169,8 @@ do_cookies_parsing_test (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 
        server = soup_test_server_new (TRUE);
@@ -212,14 +180,15 @@ main (int argc, char **argv)
        soup_uri_set_port (first_party_uri, soup_server_get_port (server));
        soup_uri_set_port (third_party_uri, soup_server_get_port (server));
 
-       do_cookies_accept_policy_test ();
-       do_cookies_parsing_test ();
+       g_test_add_func ("/cookies/accept-policy", do_cookies_accept_policy_test);
+       g_test_add_func ("/cookies/parsing", do_cookies_parsing_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (first_party_uri);
        soup_uri_free (third_party_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/date.c b/tests/date.c
index 54a59f2..6b0ff9b 100644
--- a/tests/date.c
+++ b/tests/date.c
@@ -5,7 +5,7 @@
 
 #include "test-utils.h"
 
-static gboolean check_ok (const char *strdate, SoupDate *date);
+static void check_ok (gconstpointer data);
 
 static SoupDate *
 make_date (const char *strdate)
@@ -24,10 +24,12 @@ make_date (const char *strdate)
        return date;
 }
 
-static const struct {
+typedef struct {
        SoupDateFormat format;
        const char *date;
-} good_dates[] = {
+} GoodDate;
+
+static const GoodDate good_dates[] = {
        { SOUP_DATE_HTTP,            "Sat, 06 Nov 2004 08:09:07 GMT" },
        { SOUP_DATE_COOKIE,          "Sat, 06-Nov-2004 08:09:07 GMT" },
        { SOUP_DATE_RFC2822,         "Sat, 6 Nov 2004 08:09:07 -0430" },
@@ -37,22 +39,21 @@ static const struct {
 };
 
 static void
-check_good (SoupDateFormat format, const char *strdate)
+check_good (gconstpointer data)
 {
+       GoodDate *good = (GoodDate *)data;
        SoupDate *date;
        char *strdate2;
 
-       date = make_date (strdate);
-       g_assert (date);
-       strdate2 = soup_date_to_string (date, format);
-       if (!check_ok (strdate, date))
-               return;
+       check_ok (good->date);
 
-       if (strcmp (strdate, strdate2) != 0) {
-               debug_printf (1, "  restringification failed: '%s' -> '%s'\n",
-                             strdate, strdate2);
-               errors++;
-       }
+       date = make_date (good->date);
+       strdate2 = soup_date_to_string (date, good->format);
+       soup_date_free (date);
+
+       soup_test_assert (strcmp (good->date, strdate2) == 0,
+                         "restringification failed: '%s' -> '%s'\n",
+                         good->date, strdate2);
        g_free (strdate2);
 }
 
@@ -114,30 +115,42 @@ static const char *ok_dates[] = {
        "Sat, 06 Nov 2004 08:09:7 GMT"
 };
 
+static void
+check_ok (gconstpointer data)
+{
+       const char *strdate = data;
+       SoupDate *date;
+
+       date = make_date (strdate);
+       if (!date) {
+               g_assert_true (date != NULL);
+               return;
+       }
+
+       g_assert_cmpint (date->year,   ==, 2004);
+       g_assert_cmpint (date->month,  ==, 11);
+       g_assert_cmpint (date->day,    ==, 6);
+       g_assert_cmpint (date->hour,   ==, 8);
+       g_assert_cmpint (date->minute, ==, 9);
+       g_assert_cmpint (date->second, ==, 7);
+}
+
 #define TIME_T 1099728547L
 #define TIME_T_STRING "1099728547"
 
-static gboolean
-check_ok (const char *strdate, SoupDate *date)
+static void
+check_ok_time_t (void)
 {
-       debug_printf (2, "%s\n", strdate);
+       SoupDate *date;
 
-       if (date &&
-           date->year == 2004 && date->month == 11 && date->day == 6 &&
-           date->hour == 8 && date->minute == 9 && date->second == 7) {
-               soup_date_free (date);
-               return TRUE;
-       }
+       date = soup_date_new_from_time_t (TIME_T);
 
-       debug_printf (1, "  date parsing failed for '%s'.\n", strdate);
-       if (date) {
-               debug_printf (1, "    got: %d %d %d - %d %d %d\n\n",
-                             date->year, date->month, date->day,
-                             date->hour, date->minute, date->second);
-               soup_date_free (date);
-       }
-       errors++;
-       return FALSE;
+       g_assert_cmpint (date->year,   ==, 2004);
+       g_assert_cmpint (date->month,  ==, 11);
+       g_assert_cmpint (date->day,    ==, 6);
+       g_assert_cmpint (date->hour,   ==, 8);
+       g_assert_cmpint (date->minute, ==, 9);
+       g_assert_cmpint (date->second, ==, 7);
 }
 
 static const char *bad_dates[] = {
@@ -177,25 +190,26 @@ static const char *bad_dates[] = {
 };
 
 static void
-check_bad (const char *strdate, SoupDate *date)
+check_bad (gconstpointer data)
 {
-       debug_printf (2, "%s\n", strdate);
-
-       if (!date)
-               return;
-       errors++;
+       const char *strdate = data;
+       SoupDate *date;
 
-       debug_printf (1, "  date parsing succeeded for '%s'!\n", strdate);
-       debug_printf (1, "    got: %d %d %d - %d %d %d\n\n",
-                     date->year, date->month, date->day,
-                     date->hour, date->minute, date->second);
-       soup_date_free (date);
+       date = make_date (strdate);
+       soup_test_assert (date == NULL,
+                         "date parsing succeeded for '%s': %d %d %d - %d %d %d",
+                         strdate,
+                         date->year, date->month, date->day,
+                         date->hour, date->minute, date->second);
+       g_clear_pointer (&date, soup_date_free);
 }
 
-static const struct conversion {
+typedef struct {
        const char *source;
        const char *http, *cookie, *rfc2822, *compact, *full, *xmlrpc;
-} conversions[] = {
+} DateConversion;
+
+static const DateConversion conversions[] = {
        /* SOUP_DATE_HTTP */
        { "Sat, 06 Nov 2004 08:09:07 GMT",
 
@@ -288,71 +302,40 @@ static const struct conversion {
 };
 
 static void
-check_conversion (const struct conversion *conv)
+check_conversion (gconstpointer data)
 {
+       const DateConversion *conv = data;
        SoupDate *date;
        char *str;
 
-       debug_printf (2, "%s\n", conv->source);
        date = make_date (conv->source);
        if (!date) {
-               debug_printf (1, "  date parsing failed for '%s'.\n", conv->source);
-               errors++;
+               soup_test_assert (FALSE, "date parsing failed for '%s'.", conv->source);
                return;
        }
 
        str = soup_date_to_string (date, SOUP_DATE_HTTP);
-       if (!str || strcmp (str, conv->http) != 0) {
-               debug_printf (1, "  conversion of '%s' to HTTP failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->http, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->http);
        g_free (str);
 
        str = soup_date_to_string (date, SOUP_DATE_COOKIE);
-       if (!str || strcmp (str, conv->cookie) != 0) {
-               debug_printf (1, "  conversion of '%s' to COOKIE failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->cookie, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->cookie);
        g_free (str);
 
        str = soup_date_to_string (date, SOUP_DATE_RFC2822);
-       if (!str || strcmp (str, conv->rfc2822) != 0) {
-               debug_printf (1, "  conversion of '%s' to RFC2822 failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->rfc2822, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->rfc2822);
        g_free (str);
 
        str = soup_date_to_string (date, SOUP_DATE_ISO8601_COMPACT);
-       if (!str || strcmp (str, conv->compact) != 0) {
-               debug_printf (1, "  conversion of '%s' to COMPACT failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->compact, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->compact);
        g_free (str);
 
        str = soup_date_to_string (date, SOUP_DATE_ISO8601_FULL);
-       if (!str || strcmp (str, conv->full) != 0) {
-               debug_printf (1, "  conversion of '%s' to FULL failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->full, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->full);
        g_free (str);
 
        str = soup_date_to_string (date, SOUP_DATE_ISO8601_XMLRPC);
-       if (!str || strcmp (str, conv->xmlrpc) != 0) {
-               debug_printf (1, "  conversion of '%s' to XMLRPC failed:\n"
-                             "    wanted: %s\n    got:    %s\n",
-                             conv->source, conv->xmlrpc, str ? str : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (str, ==, conv->xmlrpc);
        g_free (str);
 
        soup_date_free (date);
@@ -361,27 +344,38 @@ check_conversion (const struct conversion *conv)
 int
 main (int argc, char **argv)
 {
-       int i;
+       int i, ret;
+       char *path;
 
        test_init (argc, argv, NULL);
 
-       debug_printf (1, "Good dates:\n");
-       for (i = 0; i < G_N_ELEMENTS (good_dates); i++)
-               check_good (good_dates[i].format, good_dates[i].date);
+       for (i = 0; i < G_N_ELEMENTS (good_dates); i++) {
+               path = g_strdup_printf ("/date/good/%s", good_dates[i].date);
+               g_test_add_data_func (path, &good_dates[i], check_good);
+               g_free (path);
+       }
 
-       debug_printf (1, "\nOK dates:\n");
-       for (i = 0; i < G_N_ELEMENTS (ok_dates); i++)
-               check_ok (ok_dates[i], make_date (ok_dates[i]));
-       check_ok (TIME_T_STRING, soup_date_new_from_time_t (TIME_T));
+       for (i = 0; i < G_N_ELEMENTS (ok_dates); i++) {
+               path = g_strdup_printf ("/date/ok/%s", ok_dates[i]);
+               g_test_add_data_func (path, ok_dates[i], check_ok);
+               g_free (path);
+       }
+       g_test_add_func ("/date/ok/" TIME_T_STRING, check_ok_time_t);
+
+       for (i = 0; i < G_N_ELEMENTS (bad_dates); i++) {
+               path = g_strdup_printf ("/date/bad/%s", bad_dates[i]);
+               g_test_add_data_func (path, bad_dates[i], check_bad);
+               g_free (path);
+       }
 
-       debug_printf (1, "\nBad dates:\n");
-       for (i = 0; i < G_N_ELEMENTS (bad_dates); i++)
-               check_bad (bad_dates[i], make_date (bad_dates[i]));
+       for (i = 0; i < G_N_ELEMENTS (conversions); i++) {
+               path = g_strdup_printf ("/date/conversions/%s", conversions[i].source);
+               g_test_add_data_func (path, &conversions[i], check_conversion);
+               g_free (path);
+       }
 
-       debug_printf (1, "\nConversions:\n");
-       for (i = 0; i < G_N_ELEMENTS (conversions); i++)
-               check_conversion (&conversions[i] );
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/forms-test.c b/tests/forms-test.c
index cf8963c..5a5db28 100644
--- a/tests/forms-test.c
+++ b/tests/forms-test.c
@@ -43,6 +43,7 @@ do_hello_test (int n, gboolean extra, const char *uri)
        GPtrArray *args;
        char *title_arg = NULL, *name_arg = NULL;
        char *str_stdout = NULL;
+       GError *error = NULL;
 
        debug_printf (1, "%2d. '%s' '%s'%s: ", n * 2 + (extra ? 2 : 1),
                      tests[n].title ? tests[n].title : "(null)",
@@ -74,20 +75,12 @@ do_hello_test (int n, gboolean extra, const char *uri)
        if (g_spawn_sync (NULL, (char **)args->pdata, NULL,
                          G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
                          NULL, NULL,
-                         &str_stdout, NULL, NULL, NULL)) {
-               if (str_stdout && !strcmp (str_stdout, tests[n].result))
-                       debug_printf (1, "OK!\n");
-               else {
-                       debug_printf (1, "WRONG!\n");
-                       debug_printf (1, "  expected '%s', got '%s'\n",
-                                     tests[n].result,
-                                     str_stdout ? str_stdout : "(error)");
-                       errors++;
-               }
+                         &str_stdout, NULL, NULL, &error)) {
+               g_assert_cmpstr (str_stdout, ==, tests[n].result);
                g_free (str_stdout);
        } else {
-               debug_printf (1, "ERROR!\n");
-               errors++;
+               g_assert_no_error (error);
+               g_error_free (error);
        }
        g_ptr_array_free (args, TRUE);
        g_free (title_arg);
@@ -95,7 +88,7 @@ do_hello_test (int n, gboolean extra, const char *uri)
 }
 
 static void
-do_hello_tests (const char *uri)
+do_hello_tests (gconstpointer uri)
 {
        int n;
 
@@ -111,6 +104,7 @@ do_md5_test_curl (const char *uri, const char *file, const char *md5)
 {
        GPtrArray *args;
        char *file_arg, *str_stdout;
+       GError *error = NULL;
 
        debug_printf (1, "  via curl: ");
 
@@ -131,18 +125,11 @@ do_md5_test_curl (const char *uri, const char *file, const char *md5)
                          G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL,
                          NULL, NULL,
                          &str_stdout, NULL, NULL, NULL)) {
-               if (str_stdout && !strcmp (str_stdout, md5))
-                       debug_printf (1, "OK!\n");
-               else {
-                       debug_printf (1, "WRONG!\n");
-                       debug_printf (1, "  expected '%s', got '%s'\n",
-                                     md5, str_stdout ? str_stdout : "(error)");
-                       errors++;
-               }
+               g_assert_cmpstr (str_stdout, ==, md5);
                g_free (str_stdout);
        } else {
-               debug_printf (1, "ERROR!\n");
-               errors++;
+               g_assert_no_error (error);
+               g_error_free (error);
        }
        g_ptr_array_free (args, TRUE);
        g_free (file_arg);
@@ -178,23 +165,15 @@ do_md5_test_libsoup (const char *uri, const char *contents,
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "ERROR: Unexpected status %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       } else if (strcmp (msg->response_body->data, md5) != 0) {
-               debug_printf (1, "ERROR: Incorrect response: expected '%s' got '%s'\n",
-                             md5, msg->response_body->data);
-               errors++;
-       } else
-               debug_printf (1, "OK!\n");
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       g_assert_cmpstr (msg->response_body->data, ==, md5);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
 }
 
 static void
-do_md5_tests (const char *uri)
+do_md5_tests (gconstpointer uri)
 {
        char *contents, *md5;
        gsize length;
@@ -203,9 +182,8 @@ do_md5_tests (const char *uri)
        debug_printf (1, "\nMD5 tests (POST, multipart/form-data)\n");
 
        if (!g_file_get_contents (MD5_TEST_FILE, &contents, &length, &error)) {
-               debug_printf (1, "  ERROR: Could not read " MD5_TEST_FILE ": %s\n", error->message);
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                return;
        }
 
@@ -238,11 +216,7 @@ do_form_decode_test (void)
        tmp = g_strdup ("other");
 
        value = g_hash_table_lookup (table, "foo");
-       if (g_strcmp0 (value, "third") != 0) {
-               debug_printf (1, "  ERROR: expected '%s', got '%s'\n",
-                             "third", value ? value : "(null)");
-               errors++;
-       }
+       g_assert_cmpstr (value, ==, "third");
 
        g_free (tmp);
        g_hash_table_destroy (table);
@@ -423,6 +397,7 @@ main (int argc, char **argv)
        SoupServer *server;
        guint port;
        char *uri_str;
+       int ret = 0;
 
        test_init (argc, argv, no_test_entry);
 
@@ -437,14 +412,14 @@ main (int argc, char **argv)
 
        if (run_tests) {
                uri_str = g_strdup_printf ("http://127.0.0.1:%u/hello";, port);
-               do_hello_tests (uri_str);
-               g_free (uri_str);
+               g_test_add_data_func_full ("/forms/hello", uri_str, do_hello_tests, g_free);
 
                uri_str = g_strdup_printf ("http://127.0.0.1:%u/md5";, port);
-               do_md5_tests (uri_str);
-               g_free (uri_str);
+               g_test_add_data_func_full ("/forms/md5", uri_str, do_md5_tests, g_free);
+
+               g_test_add_func ("/forms/decode", do_form_decode_test);
 
-               do_form_decode_test ();
+               ret = g_test_run ();
        } else {
                g_print ("Listening on port %d\n", port);
                g_main_loop_run (loop);
@@ -455,7 +430,7 @@ main (int argc, char **argv)
        soup_test_server_quit_unref (server);
        if (run_tests)
                test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_CURL */
diff --git a/tests/header-parsing.c b/tests/header-parsing.c
index b02bc98..5f99831 100644
--- a/tests/header-parsing.c
+++ b/tests/header-parsing.c
@@ -717,18 +717,11 @@ static struct QValueTest {
 static const int num_qvaluetests = G_N_ELEMENTS (qvaluetests);
 
 static void
-print_header (const char *name, const char *value, gpointer data)
-{
-       debug_printf (1, "              '%s': '%s'\n", name, value);
-}
-
-static gboolean
 check_headers (Header *headers, SoupMessageHeaders *hdrs)
 {
        GSList *header_names, *h;
        SoupMessageHeadersIter iter;
        const char *name, *value;
-       gboolean ok = TRUE;
        int i;
 
        header_names = NULL;
@@ -740,34 +733,26 @@ check_headers (Header *headers, SoupMessageHeaders *hdrs)
        }
 
        for (i = 0, h = header_names; headers[i].name && h; i++, h = h->next) {
-               if (g_ascii_strcasecmp (h->data, headers[i].name) != 0) {
-                       ok = FALSE;
-                       break;
-               }
+               g_assert (g_ascii_strcasecmp (h->data, headers[i].name) == 0);
+
                value = soup_message_headers_get_list (hdrs, headers[i].name);
-               if (g_strcmp0 (value, headers[i].value) != 0) {
-                       ok = FALSE;
-                       break;
-               }
+               g_assert_cmpstr (value, ==, headers[i].value);
        }
        /* If we have remaining fields to check, they should return NULL */
        for (; headers[i].name; i++) {
                value = soup_message_headers_get_list (hdrs, headers[i].name);
-               if (value) {
-                       ok = FALSE;
-                       break;
-               }
+               g_assert_null (value);
        }
-       if (headers[i].name || h)
-               ok = FALSE;
+       g_assert_null (headers[i].name);
+       g_assert_null (h);
+
        g_slist_free (header_names);
-       return ok;
 }
 
 static void
 do_request_tests (void)
 {
-       int i, len, h;
+       int i, len;
        char *method, *path;
        SoupHTTPVersion version;
        SoupMessageHeaders *headers;
@@ -775,8 +760,6 @@ do_request_tests (void)
 
        debug_printf (1, "Request tests\n");
        for (i = 0; i < num_reqtests; i++) {
-               gboolean ok = TRUE;
-
                debug_printf (1, "%2d. %s (%s): ", i + 1, reqtests[i].description,
                              soup_status_get_phrase (reqtests[i].status));
 
@@ -790,48 +773,13 @@ do_request_tests (void)
                status = soup_headers_parse_request (reqtests[i].request, len,
                                                     headers, &method, &path,
                                                     &version);
+               g_assert_cmpint (status, ==, reqtests[i].status);
                if (SOUP_STATUS_IS_SUCCESSFUL (status)) {
-                       if ((reqtests[i].method && strcmp (reqtests[i].method, method) != 0) || 
!reqtests[i].method)
-                               ok = FALSE;
-                       if ((reqtests[i].path && strcmp (reqtests[i].path, path) != 0) || !reqtests[i].path)
-                               ok = FALSE;
-                       if (reqtests[i].version != version)
-                               ok = FALSE;
-
-                       if (!check_headers (reqtests[i].headers, headers))
-                               ok = FALSE;
-               } else {
-                       if (status != reqtests[i].status)
-                               ok = FALSE;
-               }
+                       g_assert_cmpstr (method, ==, reqtests[i].method);
+                       g_assert_cmpstr (path, ==, reqtests[i].path);
+                       g_assert_cmpint (version, ==, reqtests[i].version);
 
-               if (ok)
-                       debug_printf (1, "OK!\n");
-               else {
-                       debug_printf (1, "BAD!\n");
-                       errors++;
-                       if (reqtests[i].method) {
-                               debug_printf (1, "    expected: '%s' '%s' 'HTTP/1.%d'\n",
-                                             reqtests[i].method,
-                                             reqtests[i].path,
-                                             reqtests[i].version);
-                               for (h = 0; reqtests[i].headers[h].name; h++) {
-                                       debug_printf (1, "              '%s': '%s'\n",
-                                                     reqtests[i].headers[h].name,
-                                                     reqtests[i].headers[h].value);
-                               }
-                       } else {
-                               debug_printf (1, "    expected: %s\n",
-                                             soup_status_get_phrase (reqtests[i].status));
-                       }
-                       if (method) {
-                               debug_printf (1, "         got: '%s' '%s' 'HTTP/1.%d'\n",
-                                             method, path, version);
-                               soup_message_headers_foreach (headers, print_header, NULL);
-                       } else {
-                               debug_printf (1, "         got: %s\n",
-                                             soup_status_get_phrase (status));
-                       }
+                       check_headers (reqtests[i].headers, headers);
                }
 
                g_free (method);
@@ -844,7 +792,7 @@ do_request_tests (void)
 static void
 do_response_tests (void)
 {
-       int i, len, h;
+       int i, len;
        guint status_code;
        char *reason_phrase;
        SoupHTTPVersion version;
@@ -852,8 +800,6 @@ do_response_tests (void)
 
        debug_printf (1, "Response tests\n");
        for (i = 0; i < num_resptests; i++) {
-               gboolean ok = TRUE;
-
                debug_printf (1, "%2d. %s (%s): ", i + 1, resptests[i].description,
                              resptests[i].reason_phrase ? "should parse" : "should NOT parse");
 
@@ -867,44 +813,13 @@ do_response_tests (void)
                if (soup_headers_parse_response (resptests[i].response, len,
                                                 headers, &version,
                                                 &status_code, &reason_phrase)) {
-                       if (resptests[i].version != version)
-                               ok = FALSE;
-                       if (resptests[i].status_code != status_code)
-                               ok = FALSE;
-                       if ((resptests[i].reason_phrase && strcmp (resptests[i].reason_phrase, reason_phrase) 
!= 0) || !resptests[i].reason_phrase)
-                               ok = FALSE;
-
-                       if (!check_headers (resptests[i].headers, headers))
-                               ok = FALSE;
-               } else {
-                       if (resptests[i].reason_phrase)
-                               ok = FALSE;
-               }
+                       g_assert_cmpint (version, ==, resptests[i].version);
+                       g_assert_cmpint (status_code, ==, resptests[i].status_code);
+                       g_assert_cmpstr (reason_phrase, ==, resptests[i].reason_phrase);
 
-               if (ok)
-                       debug_printf (1, "OK!\n");
-               else {
-                       debug_printf (1, "BAD!\n");
-                       errors++;
-                       if (resptests[i].reason_phrase) {
-                               debug_printf (1, "    expected: 'HTTP/1.%d' '%03d' '%s'\n",
-                                             resptests[i].version,
-                                             resptests[i].status_code,
-                                             resptests[i].reason_phrase);
-                               for (h = 0; resptests[i].headers[h].name; h++) {
-                                       debug_printf (1, "              '%s': '%s'\n",
-                                                     resptests[i].headers[h].name,
-                                                     resptests[i].headers[h].value);
-                               }
-                       } else
-                               debug_printf (1, "    expected: parse error\n");
-                       if (reason_phrase) {
-                               debug_printf (1, "         got: 'HTTP/1.%d' '%03d' '%s'\n",
-                                             version, status_code, reason_phrase);
-                               soup_message_headers_foreach (headers, print_header, NULL);
-                       } else
-                               debug_printf (1, "         got: parse error\n");
-               }
+                       check_headers (resptests[i].headers, headers);
+               } else
+                       g_assert_null (resptests[i].reason_phrase);
 
                g_free (reason_phrase);
                soup_message_headers_free (headers);
@@ -917,7 +832,6 @@ do_qvalue_tests (void)
 {
        int i, j;
        GSList *acceptable, *unacceptable, *iter;
-       gboolean wrong;
 
        debug_printf (1, "qvalue tests\n");
        for (i = 0; i < num_qvaluetests; i++) {
@@ -928,46 +842,26 @@ do_qvalue_tests (void)
                                                             &unacceptable);
 
                debug_printf (1, "    acceptable: ");
-               wrong = FALSE;
                if (acceptable) {
                        for (iter = acceptable, j = 0; iter; iter = iter->next, j++) {
                                debug_printf (1, "%s ", (char *)iter->data);
-                               if (!qvaluetests[i].acceptable[j] ||
-                                   strcmp (iter->data, qvaluetests[i].acceptable[j]) != 0)
-                                       wrong = TRUE;
+                               g_assert_cmpstr (iter->data, ==, qvaluetests[i].acceptable[j]);
                        }
                        debug_printf (1, "\n");
                        soup_header_free_list (acceptable);
                } else
                        debug_printf (1, "(none)\n");
-               if (wrong) {
-                       debug_printf (1, "    WRONG! expected: ");
-                       for (j = 0; qvaluetests[i].acceptable[j]; j++)
-                               debug_printf (1, "%s ", qvaluetests[i].acceptable[j]);
-                       debug_printf (1, "\n");
-                       errors++;
-               }
 
                debug_printf (1, "  unacceptable: ");
-               wrong = FALSE;
                if (unacceptable) {
                        for (iter = unacceptable, j = 0; iter; iter = iter->next, j++) {
                                debug_printf (1, "%s ", (char *)iter->data);
-                               if (!qvaluetests[i].unacceptable[j] ||
-                                   strcmp (iter->data, qvaluetests[i].unacceptable[j]) != 0)
-                                       wrong = TRUE;
+                               g_assert_cmpstr (iter->data, ==, qvaluetests[i].unacceptable[j]);
                        }
                        debug_printf (1, "\n");
                        soup_header_free_list (unacceptable);
                } else
                        debug_printf (1, "(none)\n");
-               if (wrong) {
-                       debug_printf (1, "    WRONG! expected: ");
-                       for (j = 0; qvaluetests[i].unacceptable[j]; j++)
-                               debug_printf (1, "%s ", qvaluetests[i].unacceptable[j]);
-                       debug_printf (1, "\n");
-                       errors++;
-               }
 
                debug_printf (1, "\n");
        }
@@ -1002,14 +896,7 @@ do_content_disposition_tests (void)
        g_hash_table_destroy (params);
 
        header = soup_message_headers_get_one (hdrs, "Content-Disposition");
-       if (!g_strcmp0 (header, RFC5987_TEST_HEADER_ENCODED))
-               debug_printf (1, "  encoded OK\n");
-       else {
-               debug_printf (1, "  encoding FAILED!\n    expected: %s\n    got:      %s\n",
-                             RFC5987_TEST_HEADER_ENCODED,
-                             header ? header : "(none)");
-               errors++;
-       }
+       g_assert_cmpstr (header, ==, RFC5987_TEST_HEADER_ENCODED);
 
        /* UTF-8 decoding */
        soup_message_headers_clear (hdrs);
@@ -1018,22 +905,13 @@ do_content_disposition_tests (void)
        if (!soup_message_headers_get_content_disposition (hdrs,
                                                           &disposition,
                                                           &params)) {
-               debug_printf (1, "  UTF-8 decoding FAILED!\n    could not parse\n");
-               errors++;
+               soup_test_assert (FALSE, "UTF-8 decoding FAILED");
                return;
        }
        g_free (disposition);
 
        filename = g_hash_table_lookup (params, "filename");
-       if (!filename) {
-               debug_printf (1, "  UTF-8 decoding FAILED!\n    could not find filename\n");
-               errors++;
-       } else if (strcmp (filename, RFC5987_TEST_FILENAME) != 0) {
-               debug_printf (1, "  UTF-8 decoding FAILED!\n    expected: %s\n    got:      %s\n",
-                             RFC5987_TEST_FILENAME, filename);
-               errors++;
-       } else
-               debug_printf (1, "  UTF-8 decoded OK\n");
+       g_assert_cmpstr (filename, ==, RFC5987_TEST_FILENAME);
        g_hash_table_destroy (params);
 
        /* ISO-8859-1 decoding */
@@ -1043,22 +921,13 @@ do_content_disposition_tests (void)
        if (!soup_message_headers_get_content_disposition (hdrs,
                                                           &disposition,
                                                           &params)) {
-               debug_printf (1, "  iso-8859-1 decoding FAILED!\n    could not parse\n");
-               errors++;
+               soup_test_assert (FALSE, "iso-8859-1 decoding FAILED");
                return;
        }
        g_free (disposition);
 
        filename = g_hash_table_lookup (params, "filename");
-       if (!filename) {
-               debug_printf (1, "  iso-8859-1 decoding FAILED!\n    could not find filename\n");
-               errors++;
-       } else if (strcmp (filename, RFC5987_TEST_FILENAME) != 0) {
-               debug_printf (1, "  iso-8859-1 decoding FAILED!\n    expected: %s\n    got:      %s\n",
-                             RFC5987_TEST_FILENAME, filename);
-               errors++;
-       } else
-               debug_printf (1, "  iso-8859-1 decoded OK\n");
+       g_assert_cmpstr (filename, ==, RFC5987_TEST_FILENAME);
        g_hash_table_destroy (params);
 
        /* Fallback */
@@ -1068,22 +937,13 @@ do_content_disposition_tests (void)
        if (!soup_message_headers_get_content_disposition (hdrs,
                                                           &disposition,
                                                           &params)) {
-               debug_printf (1, "  fallback decoding FAILED!\n    could not parse\n");
-               errors++;
+               soup_test_assert (FALSE, "fallback decoding FAILED");
                return;
        }
        g_free (disposition);
 
        filename = g_hash_table_lookup (params, "filename");
-       if (!filename) {
-               debug_printf (1, "  fallback decoding FAILED!\n    could not find filename\n");
-               errors++;
-       } else if (strcmp (filename, RFC5987_TEST_FALLBACK_FILENAME) != 0) {
-               debug_printf (1, "  fallback decoding FAILED!\n    expected: %s\n    got:      %s\n",
-                             RFC5987_TEST_FALLBACK_FILENAME, filename);
-               errors++;
-       } else
-               debug_printf (1, "  fallback decoded OK\n");
+       g_assert_cmpstr (filename, ==, RFC5987_TEST_FALLBACK_FILENAME);
        g_hash_table_destroy (params);
 
        soup_message_headers_free (hdrs);
@@ -1104,12 +964,8 @@ do_content_disposition_tests (void)
        buffer = soup_message_body_flatten (body);
        soup_message_body_free (body);
 
-       if (strstr (buffer->data, "filename=\"token\""))
-               debug_printf (1, "  SoupMultipart encoded filename correctly\n");
-       else {
-               debug_printf (1, "  SoupMultipart encoded filename incorrectly!\n");
-               errors++;
-       }
+       g_assert_true (strstr (buffer->data, "filename=\"token\""));
+
        soup_buffer_free (buffer);
 
        debug_printf (1, "\n");
@@ -1139,14 +995,7 @@ do_content_type_tests (void)
        g_hash_table_destroy (params);
 
        header = soup_message_headers_get_one (hdrs, "Content-Type");
-       if (!g_strcmp0 (header, CONTENT_TYPE_TEST_HEADER))
-               debug_printf (1, "  encoded OK\n");
-       else {
-               debug_printf (1, "  encoding FAILED!\n    expected: %s\n    got:      %s\n",
-                             CONTENT_TYPE_TEST_HEADER,
-                             header ? header : "(none)");
-               errors++;
-       }
+       g_assert_cmpstr (header, ==, CONTENT_TYPE_TEST_HEADER);
 
        soup_message_headers_clear (hdrs);
        soup_message_headers_append (hdrs, "Content-Type",
@@ -1156,22 +1005,8 @@ do_content_type_tests (void)
                                     CONTENT_TYPE_TEST_MIME_TYPE);
 
        mime_type = soup_message_headers_get_content_type (hdrs, &params);
-       if (!mime_type) {
-               debug_printf (1, "  decoding FAILED!\n    could not parse\n");
-               errors++;
-       }
-
-       if (mime_type && strcmp (mime_type, CONTENT_TYPE_TEST_MIME_TYPE) != 0) {
-               debug_printf (1, "  decoding FAILED!\n    bad returned MIME type: %s\n",
-                             mime_type);
-               errors++;
-       } else if (params && g_hash_table_size (params) != 0) {
-               debug_printf (1, "  decoding FAILED!\n    params contained %d params (should be 0)\n",
-                             g_hash_table_size (params));
-               errors++;
-       } else
-               debug_printf (1, "  decoded OK\n");
-
+       g_assert_cmpstr (mime_type, ==, CONTENT_TYPE_TEST_MIME_TYPE);
+       g_assert_cmpint (g_hash_table_size (params), ==, 0);
        if (params)
                g_hash_table_destroy (params);
 
@@ -1179,11 +1014,7 @@ do_content_type_tests (void)
        soup_message_headers_append (hdrs, "Content-Type",
                                     CONTENT_TYPE_BAD_HEADER);
        mime_type = soup_message_headers_get_content_type (hdrs, &params);
-       if (mime_type) {
-               debug_printf (1, "  Bad content rejection FAILED!\n");
-               errors++;
-       } else
-               debug_printf (1, "  Bad content rejection OK\n");
+       g_assert_null (mime_type);
 
        soup_message_headers_free (hdrs);
 
@@ -1218,12 +1049,7 @@ do_append_param_tests (void)
                                                   test_params[i].name,
                                                   test_params[i].value);
        }
-       if (strcmp (params->str, TEST_PARAMS_RESULT) != 0) {
-               debug_printf (1, "  FAILED!\n    expected: %s\n    got: %s\n",
-                             TEST_PARAMS_RESULT, params->str);
-               errors++;
-       } else
-               debug_printf (1, "  OK\n");
+       g_assert_cmpstr (params->str, ==, TEST_PARAMS_RESULT);
        g_string_free (params, TRUE);
 
        debug_printf (1, "\n");
@@ -1254,14 +1080,12 @@ do_bad_header_tests (void)
        hdrs = soup_message_headers_new (SOUP_MESSAGE_HEADERS_MULTIPART);
        for (i = 0; i < G_N_ELEMENTS (bad_headers); i++) {
                debug_printf (1, "  %s\n", bad_headers[i].description);
-               expect_warning = TRUE;
+
+               g_test_expect_message ("libsoup", G_LOG_LEVEL_CRITICAL,
+                                      "*soup_message_headers_append*assertion*failed*");
                soup_message_headers_append (hdrs, bad_headers[i].name,
                                             bad_headers[i].value);
-               if (expect_warning) {
-                       expect_warning = FALSE;
-                       debug_printf (1, "    FAILED: soup_message_headers_append() did not reject it\n");
-                       errors++;
-               }
+               g_test_assert_expected_messages ();
        }
        soup_message_headers_free (hdrs);
 }
@@ -1269,16 +1093,20 @@ do_bad_header_tests (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 
-       do_request_tests ();
-       do_response_tests ();
-       do_qvalue_tests ();
-       do_content_disposition_tests ();
-       do_content_type_tests ();
-       do_append_param_tests ();
-       do_bad_header_tests ();
+       g_test_add_func ("/header-parsing/request", do_request_tests);
+       g_test_add_func ("/header-parsing/response", do_response_tests);
+       g_test_add_func ("/header-parsing/qvalue", do_qvalue_tests);
+       g_test_add_func ("/header-parsing/content-disposition", do_content_disposition_tests);
+       g_test_add_func ("/header-parsing/content-type", do_content_type_tests);
+       g_test_add_func ("/header-parsing/append-param", do_append_param_tests);
+       g_test_add_func ("/header-parsing/bad", do_bad_header_tests);
+
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/misc-test.c b/tests/misc-test.c
index 2aaa2cd..46c9cb1 100644
--- a/tests/misc-test.c
+++ b/tests/misc-test.c
@@ -112,26 +112,12 @@ do_host_test (void)
 
        soup_test_session_abort_unref (session);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (one->status_code)) {
-               debug_printf (1, "  Message 1 failed: %d %s\n",
-                             one->status_code, one->reason_phrase);
-               errors++;
-       } else if (strcmp (one->response_body->data, "index") != 0) {
-               debug_printf (1, "  Unexpected response to message 1: '%s'\n",
-                             one->response_body->data);
-               errors++;
-       }
+       soup_test_assert_message_status (one, SOUP_STATUS_OK);
+       g_assert_cmpstr (one->response_body->data, ==, "index");
        g_object_unref (one);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (two->status_code)) {
-               debug_printf (1, "  Message 2 failed: %d %s\n",
-                             two->status_code, two->reason_phrase);
-               errors++;
-       } else if (strcmp (two->response_body->data, "foo-index") != 0) {
-               debug_printf (1, "  Unexpected response to message 2: '%s'\n",
-                             two->response_body->data);
-               errors++;
-       }
+       soup_test_assert_message_status (two, SOUP_STATUS_OK);
+       g_assert_cmpstr (two->response_body->data, ==, "foo-index");
        g_object_unref (two);
 }
 
@@ -143,11 +129,7 @@ static void
 cu_one_completed (SoupSession *session, SoupMessage *msg, gpointer loop)
 {
        debug_printf (2, "  Message 1 completed\n");
-       if (msg->status_code != SOUP_STATUS_CANT_CONNECT) {
-               debug_printf (1, "  Unexpected status on Message 1: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANT_CONNECT);
        g_object_unref (session);
 }
 
@@ -162,11 +144,7 @@ static void
 cu_two_completed (SoupSession *session, SoupMessage *msg, gpointer loop)
 {
        debug_printf (2, "  Message 2 completed\n");
-       if (msg->status_code != SOUP_STATUS_CANT_CONNECT) {
-               debug_printf (1, "  Unexpected status on Message 2: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANT_CONNECT);
        g_idle_add (cu_idle_quit, loop); 
 }
 
@@ -210,22 +188,19 @@ do_callback_unref_test (void)
        g_main_loop_run (loop);
        g_main_loop_unref (loop);
 
+       g_assert_null (session);
        if (session) {
                g_object_remove_weak_pointer (G_OBJECT (session), (gpointer *)&session);
-               debug_printf (1, "  Session not destroyed?\n");
-               errors++;
                g_object_unref (session);
        }
+       g_assert_null (one);
        if (one) {
                g_object_remove_weak_pointer (G_OBJECT (one), (gpointer *)&one);
-               debug_printf (1, "  Message 1 not destroyed?\n");
-               errors++;
                g_object_unref (one);
        }
+       g_assert_null (two);
        if (two) {
                g_object_remove_weak_pointer (G_OBJECT (two), (gpointer *)&two);
-               debug_printf (1, "  Message 2 not destroyed?\n");
-               errors++;
                g_object_unref (two);
        }
 
@@ -239,14 +214,8 @@ cur_one_completed (GObject *source, GAsyncResult *result, gpointer session)
        GError *error = NULL;
 
        debug_printf (2, "  Request 1 completed\n");
-       if (soup_request_send_finish (one, result, &error)) {
-               debug_printf (1, "  Request 1 succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED)) {
-               debug_printf (1, "  Unexpected error on Request 1: %s\n",
-                             error->message);
-               errors++;
-       }
+       soup_request_send_finish (one, result, &error);
+       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED);
        g_clear_error (&error);
 
        g_object_unref (session);
@@ -266,14 +235,8 @@ cur_two_completed (GObject *source, GAsyncResult *result, gpointer loop)
        GError *error = NULL;
 
        debug_printf (2, "  Request 2 completed\n");
-       if (soup_request_send_finish (two, result, &error)) {
-               debug_printf (1, "  Request 2 succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED)) {
-               debug_printf (1, "  Unexpected error on Request 2: %s\n",
-                             error->message);
-               errors++;
-       }
+       soup_request_send_finish (two, result, &error);
+       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CONNECTION_REFUSED);
        g_clear_error (&error);
 
        g_idle_add (cur_idle_quit, loop); 
@@ -323,22 +286,19 @@ do_callback_unref_req_test (void)
        g_main_loop_run (loop);
        g_main_loop_unref (loop);
 
+       g_assert_null (session);
        if (session) {
                g_object_remove_weak_pointer (G_OBJECT (session), (gpointer *)&session);
-               debug_printf (1, "  Session not destroyed?\n");
-               errors++;
                g_object_unref (session);
        }
+       g_assert_null (one);
        if (one) {
                g_object_remove_weak_pointer (G_OBJECT (one), (gpointer *)&one);
-               debug_printf (1, "  Request 1 not destroyed?\n");
-               errors++;
                g_object_unref (one);
        }
+       g_assert_null (two);
        if (two) {
                g_object_remove_weak_pointer (G_OBJECT (two), (gpointer *)&two);
-               debug_printf (1, "  Request 2 not destroyed?\n");
-               errors++;
                g_object_unref (two);
        }
 
@@ -353,14 +313,14 @@ static void
 ensure_no_signal_handlers (SoupMessage *msg, guint *signal_ids, guint n_signal_ids)
 {
        int i;
+       guint id;
 
        for (i = 0; i < n_signal_ids; i++) {
-               if (g_signal_handler_find (msg, G_SIGNAL_MATCH_ID, signal_ids[i],
-                                          0, NULL, NULL, NULL)) {
-                       debug_printf (1, "    Message has handler for '%s'\n",
-                                     g_signal_name (signal_ids[i]));
-                       errors++;
-               }
+               id = g_signal_handler_find (msg, G_SIGNAL_MATCH_ID, signal_ids[i],
+                                           0, NULL, NULL, NULL);
+               soup_test_assert (id == 0,
+                                 "message has handler for '%s'",
+                                 g_signal_name (signal_ids[i]));
        }
 }
 
@@ -401,10 +361,7 @@ do_msg_reuse_test (void)
        soup_message_set_uri (msg, uri);
        soup_uri_free (uri);
        soup_session_send_message (session, msg);
-       if (!soup_uri_equal (soup_message_get_uri (msg), base_uri)) {
-               debug_printf (1, "    Message did not get redirected!\n");
-               errors++;
-       }
+       g_assert_true (soup_uri_equal (soup_message_get_uri (msg), base_uri));
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        debug_printf (1, "  Auth message\n");
@@ -412,10 +369,7 @@ do_msg_reuse_test (void)
        soup_message_set_uri (msg, uri);
        soup_uri_free (uri);
        soup_session_send_message (session, msg);
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    Message did not get authenticated!\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        ensure_no_signal_handlers (msg, signal_ids, n_signal_ids);
 
        /* One last try to make sure the auth stuff got cleaned up */
@@ -434,11 +388,7 @@ static void
 ea_msg_completed_one (SoupSession *session, SoupMessage *msg, gpointer loop)
 {
        debug_printf (2, "  Message 1 completed\n");
-       if (msg->status_code != SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "  Unexpected status on Message 1: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED);
        g_main_loop_quit (loop);
 }
 
@@ -509,11 +459,7 @@ do_early_abort_test (void)
        soup_session_send_message (session, msg);
        debug_printf (2, "  Message 2 completed\n");
 
-       if (msg->status_code != SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED);
        g_object_unref (msg);
 
        while (g_main_context_pending (context))
@@ -529,11 +475,7 @@ do_early_abort_test (void)
        soup_session_send_message (session, msg);
        debug_printf (2, "  Message 3 completed\n");
 
-       if (msg->status_code != SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED);
        g_object_unref (msg);
 
        while (g_main_context_pending (context))
@@ -548,14 +490,8 @@ ear_one_completed (GObject *source, GAsyncResult *result, gpointer user_data)
        GError *error = NULL;
 
        debug_printf (2, "  Request 1 completed\n");
-       if (soup_request_send_finish (SOUP_REQUEST (source), result, &error)) {
-               debug_printf (1, "  Request 1 succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANCELLED)) {
-               debug_printf (1, "  Unexpected error on Request 1: %s\n",
-                             error->message);
-               errors++;
-       }
+       soup_request_send_finish (SOUP_REQUEST (source), result, &error);
+       g_assert_error (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANCELLED);
        g_clear_error (&error);
 }
 
@@ -565,14 +501,8 @@ ear_two_completed (GObject *source, GAsyncResult *result, gpointer loop)
        GError *error = NULL;
 
        debug_printf (2, "  Request 2 completed\n");
-       if (soup_request_send_finish (SOUP_REQUEST (source), result, &error)) {
-               debug_printf (1, "  Request 2 succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANCELLED)) {
-               debug_printf (1, "  Unexpected error on Request 2: %s\n",
-                             error->message);
-               errors++;
-       }
+       soup_request_send_finish (SOUP_REQUEST (source), result, &error);
+       g_assert_error (error, SOUP_HTTP_ERROR, SOUP_STATUS_CANCELLED);
        g_clear_error (&error);
 
        g_main_loop_quit (loop);
@@ -584,14 +514,8 @@ ear_three_completed (GObject *source, GAsyncResult *result, gpointer loop)
        GError *error = NULL;
 
        debug_printf (2, "  Request 3 completed\n");
-       if (soup_request_send_finish (SOUP_REQUEST (source), result, &error)) {
-               debug_printf (1, "  Request 3 succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-               debug_printf (1, "  Unexpected error on Request 3: %s\n",
-                             error->message);
-               errors++;
-       }
+       soup_request_send_finish (SOUP_REQUEST (source), result, &error);
+       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
        g_clear_error (&error);
 
        g_main_loop_quit (loop);
@@ -683,21 +607,10 @@ do_one_accept_language_test (const char *language, const char *expected_header)
        soup_session_send_message (session, msg);
        soup_test_session_abort_unref (session);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    Message failed? %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        val = soup_message_headers_get_list (msg->request_headers,
                                             "Accept-Language");
-       if (!val) {
-               debug_printf (1, "    No Accept-Language set!\n");
-               errors++;
-       } else if (strcmp (val, expected_header) != 0) {
-               debug_printf (1, "    Wrong Accept-Language: expected '%s', got '%s'\n",
-                             expected_header, val);
-               errors++;
-       }
+       g_assert_cmpstr (val, ==, expected_header);
 
        g_object_unref (msg);
 }
@@ -780,11 +693,7 @@ do_cancel_while_reading_test_for_session (SoupSession *session)
        while (!done)
                g_main_context_iteration (NULL, TRUE);
 
-       if (msg->status_code != SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "      FAILED: %d %s (expected Cancelled)\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED);
        g_object_unref (msg);
 
        if (thread)
@@ -824,14 +733,7 @@ do_cancel_while_reading_req_test_for_session (SoupSession *session,
 
        cancellable = g_cancellable_new ();
        soup_test_request_send (req, cancellable, flags, &error);
-       if (!error) {
-               debug_printf (1, "  Request succeeded?\n");
-               errors++;
-       } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-               debug_printf (1, "  Unexpected error: %s\n",
-                             error->message);
-               errors++;
-       }
+       g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
        g_clear_error (&error);
 
        g_object_unref (req);
@@ -910,20 +812,11 @@ do_aliases_test_for_session (SoupSession *session,
 
        redirected_protocol = soup_message_headers_get_one (msg->response_headers, "X-Redirected-Protocol");
 
-       if (g_strcmp0 (redirect_protocol, redirected_protocol)) {
-               debug_printf (1, "    redirect went to %s, should have gone to %s!\n",
-                             redirected_protocol ? redirected_protocol : "(none)",
-                             redirect_protocol ? redirect_protocol : "(none)");
-               errors++;
-       } else if (redirect_protocol && !SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    msg failed? (%d %s)\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       } else if (!redirect_protocol && SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    msg succeeded? (%d %s)\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       g_assert_cmpstr (redirect_protocol, ==, redirected_protocol);
+       if (redirect_protocol)
+               soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       else
+               soup_test_assert_message_status (msg, SOUP_STATUS_FOUND);
 
        g_object_unref (msg);
 }
@@ -982,10 +875,8 @@ do_idle_on_dispose_test (void)
 
        g_object_run_dispose (G_OBJECT (session));
 
-       if (g_main_context_iteration (async_context, FALSE)) {
-               debug_printf (1, "  idle was queued!\n");
-               errors++;
-       }
+       if (g_main_context_iteration (async_context, FALSE))
+               soup_test_assert (FALSE, "idle was queued");
 
        g_object_unref (session);
        g_main_context_unref (async_context);
@@ -1009,16 +900,14 @@ do_pause_abort_test (void)
        g_object_add_weak_pointer (G_OBJECT (msg), &ptr);
        soup_test_session_abort_unref (session);
 
-       if (ptr) {
-               debug_printf (1, "  msg was leaked\n");
-               errors++;
-       }
+       g_assert_null (ptr);
 }
 
 int
 main (int argc, char **argv)
 {
        SoupAuthDomain *auth_domain;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -1042,18 +931,20 @@ main (int argc, char **argv)
                soup_uri_set_port (ssl_base_uri, soup_server_get_port (ssl_server));
        }
 
-       do_host_test ();
-       do_callback_unref_test ();
-       do_callback_unref_req_test ();
-       do_msg_reuse_test ();
-       do_early_abort_test ();
-       do_early_abort_req_test ();
-       do_accept_language_test ();
-       do_cancel_while_reading_test ();
-       do_cancel_while_reading_req_test ();
-       do_aliases_test ();
-       do_idle_on_dispose_test ();
-       do_pause_abort_test ();
+       g_test_add_func ("/misc/host", do_host_test);
+       g_test_add_func ("/misc/callback-unref/msg", do_callback_unref_test);
+       g_test_add_func ("/misc/callback-unref/req", do_callback_unref_req_test);
+       g_test_add_func ("/misc/msg-reuse", do_msg_reuse_test);
+       g_test_add_func ("/misc/early-abort/msg", do_early_abort_test);
+       g_test_add_func ("/misc/early-abort/req", do_early_abort_req_test);
+       g_test_add_func ("/misc/accept-language", do_accept_language_test);
+       g_test_add_func ("/misc/cancel-while-reading/msg", do_cancel_while_reading_test);
+       g_test_add_func ("/misc/cancel-while-reading/req", do_cancel_while_reading_req_test);
+       g_test_add_func ("/misc/aliases", do_aliases_test);
+       g_test_add_func ("/misc/idle-on-dispose", do_idle_on_dispose_test);
+       g_test_add_func ("/misc/pause-abort", do_pause_abort_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
@@ -1063,6 +954,5 @@ main (int argc, char **argv)
                soup_test_server_quit_unref (ssl_server);
        }
 
-       test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/multipart-test.c b/tests/multipart-test.c
index bfe4f5b..b5ab813 100644
--- a/tests/multipart-test.c
+++ b/tests/multipart-test.c
@@ -87,10 +87,8 @@ content_sniffed (SoupMessage *msg, char *content_type, GHashTable *params, int *
 static void
 check_is_next (gboolean is_next)
 {
-       if (!is_next) {
-               debug_printf (1, "  expected a header, but there are no more headers\n");
-               errors++;
-       }
+       soup_test_assert (is_next,
+                         "expected a header, but there are no more headers");
 }
 
 static void
@@ -112,15 +110,8 @@ got_headers (SoupMessage *msg, int *headers_count)
                check_is_next (is_next);
        }
 
-       if (!g_str_equal (name, "Content-Type")) {
-               debug_printf (1, "  expected 'Content-Type' got %s\n", name);
-               errors++;
-       }
-
-       if (!g_str_equal (value, "multipart/x-mixed-replace; boundary=cut-here")) {
-               debug_printf (1, "  expected 'multipart/x-mixed-replace; boundary=cut-here' got %s\n", value);
-               errors++;
-       }
+       g_assert_cmpstr (name, ==, "Content-Type");
+       g_assert_cmpstr (value, ==, "multipart/x-mixed-replace; boundary=cut-here");
 }
 
 static void
@@ -129,12 +120,11 @@ read_cb (GObject *source, GAsyncResult *asyncResult, gpointer data)
        GMainLoop *loop = (GMainLoop*)data;
        GInputStream *stream = G_INPUT_STREAM (source);
        GError *error = NULL;
-       gssize bytes_read = g_input_stream_read_finish (stream, asyncResult, &error);
+       gssize bytes_read;
 
+       bytes_read = g_input_stream_read_finish (stream, asyncResult, &error);
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed read: %s\n", error->message);
-               errors++;
-
                g_object_unref (stream);
                g_main_loop_quit (loop);
                return;
@@ -142,13 +132,8 @@ read_cb (GObject *source, GAsyncResult *asyncResult, gpointer data)
 
        if (!bytes_read) {
                g_input_stream_close (stream, NULL, &error);
+               g_assert_no_error (error);
                g_object_unref (stream);
-
-               if (error) {
-                       debug_printf (1, "  failed close: %s\n", error->message);
-                       errors++;
-               }
-
                g_main_loop_quit (loop);
                return;
        }
@@ -167,11 +152,8 @@ no_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
        GInputStream* in;
 
        in = soup_request_send_finish (request, res, &error);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed send: %s\n", error->message);
-               errors++;
-
                g_main_loop_quit (loop);
                return;
        }
@@ -188,10 +170,7 @@ multipart_close_part_cb (GObject *source, GAsyncResult *res, gpointer data)
        GError *error = NULL;
 
        g_input_stream_close_finish (in, res, &error);
-       if (error) {
-               debug_printf (1, "  error closing stream: %s\n", error->message);
-               errors++;
-       }
+       g_assert_no_error (error);
 }
 
 static void multipart_next_part_cb (GObject *source,
@@ -203,32 +182,20 @@ check_read (gsize nread, unsigned passes)
 {
        switch (passes) {
        case 0:
-               if (nread != 30) {
-                       debug_printf (1, "  expected to read 30 bytes, got: %d\n", (int)nread);
-                       errors++;
-               }
+               g_assert_cmpint (nread, ==, 30);
                break;
        case 1:
-               if (nread != 10) {
-                       debug_printf (1, "  expected to read 10 bytes, got: %d\n", (int)nread);
-                       errors++;
-               }
+               g_assert_cmpint (nread, ==, 10);
                break;
        case 2:
-               if (nread != 24) {
-                       debug_printf (1, "  expected to read 24 bytes, got: %d\n", (int)nread);
-                       errors++;
-               }
+               g_assert_cmpint (nread, ==, 24);
                break;
        case 3:
-               if (nread != 34) {
-                       debug_printf (1, "  expected to read 34 bytes, got: %d\n", (int)nread);
-                       errors++;
-               }
+               g_assert_cmpint (nread, ==, 34);
                break;
        default:
-               debug_printf (1, "  unexpected read of size: %d\n", (int)nread);
-               errors++;
+               soup_test_assert (FALSE, "unexpected read of size: %d", (int)nread);
+               break;
        }
 }
 
@@ -242,11 +209,8 @@ multipart_read_cb (GObject *source, GAsyncResult *asyncResult, gpointer data)
        gssize bytes_read;
 
        bytes_read = g_input_stream_read_finish (in, asyncResult, &error);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed read: %s\n", error->message);
-               errors++;
-
                g_input_stream_close_async (in, G_PRIORITY_DEFAULT, NULL,
                                            multipart_close_part_cb, NULL);
                g_object_unref (in);
@@ -292,43 +256,22 @@ check_headers (SoupMultipartInputStream* multipart, unsigned passes)
                is_next = soup_message_headers_iter_next (&iter, &name, &value);
                check_is_next (is_next);
 
-               if (!g_str_equal (name, "Content-Type")) {
-                       debug_printf (1, "  [0] expected 'Content-Type' got %s\n", name);
-                       errors++;
-               }
-
-               if (!g_str_equal (value, "text/html")) {
-                       debug_printf (1, "  [0] expected 'text/html' got %s\n", value);
-                       errors++;
-               }
+               g_assert_cmpstr (name, ==, "Content-Type");
+               g_assert_cmpstr (value, ==, "text/html");
 
                is_next = soup_message_headers_iter_next (&iter, &name, &value);
                check_is_next (is_next);
 
-               if (!g_str_equal (name, "Content-Length")) {
-                       debug_printf (1, "  [0] expected 'Content-Length' got %s\n", name);
-                       errors++;
-               }
-
-               if (!g_str_equal (value, "30")) {
-                       debug_printf (1, "  [0] expected '30' got %s\n", value);
-                       errors++;
-               }
+               g_assert_cmpstr (name, ==, "Content-Length");
+               g_assert_cmpstr (value, ==, "30");
 
                break;
        case 1:
                is_next = soup_message_headers_iter_next (&iter, &name, &value);
                check_is_next (is_next);
 
-               if (!g_str_equal (name, "Content-Length")) {
-                       debug_printf (1, "  [1] expected 'Content-Length' got %s\n", name);
-                       errors++;
-               }
-
-               if (!g_str_equal (value, "10")) {
-                       debug_printf (1, "  [1] expected '10' got %s\n", value);
-                       errors++;
-               }
+               g_assert_cmpstr (name, ==, "Content-Length");
+               g_assert_cmpstr (value, ==, "10");
 
                break;
        case 2:
@@ -336,19 +279,12 @@ check_headers (SoupMultipartInputStream* multipart, unsigned passes)
                is_next = soup_message_headers_iter_next (&iter, &name, &value);
                check_is_next (is_next);
 
-               if (!g_str_equal (name, "Content-Type")) {
-                       debug_printf (1, "  [%d] expected 'Content-Type' got %s\n", passes, name);
-                       errors++;
-               }
-
-               if (!g_str_equal (value, "text/css")) {
-                       debug_printf (1, "  [%d] expected 'text/html' got %s\n", passes, value);
-                       errors++;
-               }
+               g_assert_cmpstr (name, ==, "Content-Type");
+               g_assert_cmpstr (value, ==, "text/css");
 
                break;
        default:
-               debug_printf (1, "  unexpected part received\n");
+               soup_test_assert (FALSE, "unexpected part received");
                break;
        }
 }
@@ -364,23 +300,16 @@ multipart_next_part_cb (GObject *source, GAsyncResult *res, gpointer data)
        g_assert (SOUP_MULTIPART_INPUT_STREAM (source) == multipart);
 
        in = soup_multipart_input_stream_next_part_finish (multipart, res, &error);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed next part: %s\n", error->message);
                g_clear_error (&error);
-               errors++;
-
                g_object_unref (multipart);
                g_main_loop_quit (loop);
                return;
        }
 
        if (!in) {
-               if (passes != 4) {
-                       debug_printf (1, "  expected 4 parts, got %u\n", passes);
-                       errors++;
-               }
-
+               g_assert_cmpint (passes, ==, 4);
                g_object_unref (multipart);
                g_main_loop_quit (loop);
                return;
@@ -406,19 +335,17 @@ multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
        SoupMessage *message;
 
        in = soup_request_send_finish (request, res, &error);
-       message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
-       multipart = soup_multipart_input_stream_new (message, in);
-       g_object_unref (message);
-       g_object_unref (in);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed send: %s\n", error->message);
-               errors++;
-
                g_main_loop_quit (loop);
                return;
        }
 
+       message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
+       multipart = soup_multipart_input_stream_new (message, in);
+       g_object_unref (message);
+       g_object_unref (in);
+
        if (g_object_get_data (source, "multipart-small-reads"))
                g_object_set_data (G_OBJECT (multipart), "multipart-small-reads", GINT_TO_POINTER(1));
 
@@ -438,25 +365,21 @@ sync_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
        gsize bytes_read;
 
        in = soup_request_send_finish (request, res, &error);
-       message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
-       multipart = soup_multipart_input_stream_new (message, in);
-       g_object_unref (message);
-       g_object_unref (in);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "  failed send: %s\n", error->message);
-               errors++;
-
                g_main_loop_quit (loop);
                return;
        }
 
+       message = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
+       multipart = soup_multipart_input_stream_new (message, in);
+       g_object_unref (message);
+       g_object_unref (in);
+
        while (TRUE) {
                in = soup_multipart_input_stream_next_part (multipart, NULL, &error);
-
+               g_assert_no_error (error);
                if (error) {
-                       debug_printf (1, "  failed sync next part: %s\n", error->message);
-                       errors++;
                        g_clear_error (&error);
                        break;
                }
@@ -467,10 +390,8 @@ sync_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
                check_headers (multipart, passes);
 
                g_input_stream_read_all (in, (void*)buffer, sizeof (buffer), &bytes_read, NULL, &error);
-
+               g_assert_no_error (error);
                if (error) {
-                       debug_printf (1, "  failed sync read: %s\n", error->message);
-                       errors++;
                        g_clear_error (&error);
                        g_object_unref (in);
                        break;
@@ -482,10 +403,7 @@ sync_multipart_handling_cb (GObject *source, GAsyncResult *res, gpointer data)
                g_object_unref (in);
        }
 
-       if (passes != 4) {
-               debug_printf (1, "  expected 4 parts, got %u\n", passes);
-               errors++;
-       }
+       g_assert_cmpint (passes, ==, 4);
 
        g_main_loop_quit (loop);
        g_object_unref (multipart);
@@ -505,21 +423,29 @@ multipart_mode_to_string (MultipartMode mode)
 }
 
 static void
-test_multipart (int headers_expected, int sniffed_expected, MultipartMode multipart_mode)
+test_multipart (gconstpointer data)
 {
-       GError* error = NULL;
-       SoupRequest* request = soup_session_request (session, base_uri_string, &error);
-
-       SoupMessage *msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
-       GMainLoop *loop = g_main_loop_new (NULL, TRUE);
+       int headers_expected = 1, sniffed_expected = 1;
+       MultipartMode multipart_mode = GPOINTER_TO_INT (data);
+       SoupRequest* request;
+       SoupMessage *msg;
+       GMainLoop *loop;
        int headers_count = 0;
        int sniffed_count = 0;
        GHashTable *params;
        const char *content_type;
        gboolean message_is_multipart = FALSE;
+       GError* error = NULL;
 
        debug_printf (1, "test_multipart(%s)\n", multipart_mode_to_string (multipart_mode));
 
+       request = soup_session_request (session, base_uri_string, &error);
+       g_assert_no_error (error);
+       if (error)
+               return;
+
+       msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
+
        /* This is used to track the number of parts. */
        passes = 0;
 
@@ -533,6 +459,8 @@ test_multipart (int headers_expected, int sniffed_expected, MultipartMode multip
        g_signal_connect (msg, "content-sniffed",
                          G_CALLBACK (content_sniffed), &sniffed_count);
 
+       loop = g_main_loop_new (NULL, TRUE);
+
        if (multipart_mode == ASYNC_MULTIPART)
                soup_request_send_async (request, NULL, multipart_handling_cb, loop);
        else if (multipart_mode == ASYNC_MULTIPART_SMALL_READS) {
@@ -554,25 +482,9 @@ test_multipart (int headers_expected, int sniffed_expected, MultipartMode multip
        }
        g_clear_pointer (&params, g_hash_table_unref);
 
-       if (!message_is_multipart) {
-               debug_printf (1,
-                             "  Header does not indicate a multipart message!\n");
-               errors++;
-       }
-
-       if (headers_count != headers_expected) {
-               debug_printf (1,
-                             "  expected got_header %d times, got %d!\n",
-                             headers_expected, headers_count);
-               errors++;
-       }
-
-       if (sniffed_count != sniffed_expected) {
-               debug_printf (1,
-                             "  expected content_sniffed %d times, got %d!\n",
-                             sniffed_expected, sniffed_count);
-               errors++;
-       }
+       g_assert_true (message_is_multipart);
+       g_assert_cmpint (headers_count, ==, headers_expected);
+       g_assert_cmpint (sniffed_count, ==, sniffed_expected);
 
        g_object_unref (msg);
        g_object_unref (request);
@@ -583,6 +495,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -604,10 +517,12 @@ main (int argc, char **argv)
                                         NULL);
        soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);
 
-       test_multipart (1, 1, NO_MULTIPART);
-       test_multipart (1, 1, SYNC_MULTIPART);
-       test_multipart (1, 1, ASYNC_MULTIPART);
-       test_multipart (1, 1, ASYNC_MULTIPART_SMALL_READS);
+       g_test_add_data_func ("/multipart/no", GINT_TO_POINTER (NO_MULTIPART), test_multipart);
+       g_test_add_data_func ("/multipart/sync", GINT_TO_POINTER (SYNC_MULTIPART), test_multipart);
+       g_test_add_data_func ("/multipart/async", GINT_TO_POINTER (ASYNC_MULTIPART), test_multipart);
+       g_test_add_data_func ("/multipart/async-small-reads", GINT_TO_POINTER (ASYNC_MULTIPART_SMALL_READS), 
test_multipart);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        g_free (base_uri_string);
@@ -615,6 +530,7 @@ main (int argc, char **argv)
 
        soup_test_session_abort_unref (session);
        soup_test_server_quit_unref (server);
+
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/no-ssl-test.c b/tests/no-ssl-test.c
index ab1bdc3..5944b91 100644
--- a/tests/no-ssl-test.c
+++ b/tests/no-ssl-test.c
@@ -3,38 +3,28 @@
 #include "test-utils.h"
 
 static void
-do_ssl_test_for_session (SoupSession *session, char *uri)
+do_ssl_test_for_session (SoupSession *session, const char *uri)
 {
        SoupMessage *msg;
-       GTlsCertificate *cert;
+       GTlsCertificate *cert = NULL;
        GTlsCertificateFlags flags;
+       gboolean is_https;
 
        msg = soup_message_new ("GET", uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_SSL_FAILED) {
-               debug_printf (1, "    Unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-
-       if (soup_message_get_https_status (msg, &cert, &flags)) {
-               debug_printf (1, "    get_http_status() returned TRUE? (flags %x)\n", flags);
-               errors++;
-               if (cert) {
-                       debug_printf (1, "    Got GTlsCertificate?\n");
-                       errors++;
-               }
-       }
-       if (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED) {
-               debug_printf (1, "    CERTIFICATE_TRUSTED set?\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_SSL_FAILED);
+
+       is_https = soup_message_get_https_status (msg, &cert, &flags);
+       soup_test_assert (!is_https, "get_http_status() returned TRUE? (flags %x)", flags);
+
+       g_assert_null (cert);
+       g_assert_false (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED);
 
        g_object_unref (msg);
 }
 
 static void
-do_ssl_tests (char *uri)
+do_ssl_tests (gconstpointer uri)
 {
        SoupSession *session;
 
@@ -73,20 +63,9 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (use_system) {
-               debug_printf (1, "  ssl-use-system-ca-file defaults to TRUE?\n");
-               errors++;
-       }
-       if (tlsdb) {
-               debug_printf (1, "  tls-database set by default?\n");
-               errors++;
-               g_object_unref (tlsdb);
-       }
-       if (ca_file) {
-               debug_printf (1, "  ca-file set by default?\n");
-               errors++;
-               g_free (ca_file);
-       }
+       soup_test_assert (!use_system, "ssl-use-system-ca-file defaults to TRUE");
+       soup_test_assert (tlsdb == NULL, "tls-database set by default");
+       soup_test_assert (ca_file == NULL, "ca-file set by default");
 
        g_object_set (G_OBJECT (session),
                      "ssl-use-system-ca-file", TRUE,
@@ -94,11 +73,7 @@ do_session_property_tests (void)
        g_object_get (G_OBJECT (session),
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (ca_file) {
-               debug_printf (1, "  setting ssl-use-system-ca-file set ssl-ca-file\n");
-               errors++;
-               g_free (ca_file);
-       }
+       soup_test_assert (ca_file == NULL, "setting ssl-use-system-ca-file set ssl-ca-file");
 
        g_object_set (G_OBJECT (session),
                      "ssl-ca-file", SRCDIR "/test-cert.pem",
@@ -108,20 +83,9 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (ca_file) {
-               debug_printf (1, "  setting ssl-ca-file did not fail\n");
-               errors++;
-               g_free (ca_file);
-       }
-       if (use_system) {
-               debug_printf (1, "  setting ssl-ca-file set ssl-use-system-ca-file\n");
-               errors++;
-       }
-       if (tlsdb) {
-               debug_printf (1, "  setting ssl-ca-file set tls-database\n");
-               errors++;
-               g_object_unref (tlsdb);
-       }
+       soup_test_assert (ca_file == NULL, "setting ssl-ca-file did not fail");
+       soup_test_assert (!use_system, "setting ssl-ca-file set ssl-use-system-ca-file");
+       soup_test_assert (tlsdb == NULL, "setting ssl-ca-file set tls-database");
 
        g_object_set (G_OBJECT (session),
                      "tls-database", NULL,
@@ -131,20 +95,9 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (tlsdb) {
-               debug_printf (1, "  setting tls-database NULL failed\n");
-               errors++;
-               g_object_unref (tlsdb);
-       }
-       if (use_system) {
-               debug_printf (1, "  setting tls-database NULL set ssl-use-system-ca-file\n");
-               errors++;
-       }
-       if (ca_file) {
-               debug_printf (1, "  setting tls-database NULL set ssl-ca-file\n");
-               errors++;
-               g_free (ca_file);
-       }
+       soup_test_assert (tlsdb == NULL, "setting tls-database NULL failed");
+       soup_test_assert (!use_system, "setting tls-database NULL set ssl-use-system-ca-file");
+       soup_test_assert (ca_file == NULL, "setting tls-database NULL set ssl-ca-file");
 
        soup_test_session_abort_unref (session);
 }
@@ -168,6 +121,7 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        char *uri;
+       int ret;
 
        /* Force this test to use the dummy TLS backend */
        g_setenv ("GIO_USE_TLS", "dummy", TRUE);
@@ -183,12 +137,14 @@ main (int argc, char **argv)
        uri = g_strdup_printf ("https://127.0.0.1:%u/";,
                               soup_server_get_port (server));
 
-       do_session_property_tests ();
-       do_ssl_tests (uri);
+       g_test_add_func ("/no-ssl/session-properties", do_session_property_tests);
+       g_test_add_data_func ("/no-ssl/request-error", uri, do_ssl_tests);
+
+       ret = g_test_run ();
 
        g_free (uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c
index f67a3d1..3987927 100644
--- a/tests/ntlm-test.c
+++ b/tests/ntlm-test.c
@@ -248,77 +248,59 @@ do_message (SoupSession *session, SoupURI *base_uri, const char *path,
 
        if (state.got_ntlm_prompt) {
                debug_printf (1, " NTLM_PROMPT");
-               if (!get_ntlm_prompt) {
+               if (!get_ntlm_prompt)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (get_ntlm_prompt) {
+       } else if (get_ntlm_prompt)
                debug_printf (1, " no-ntlm-prompt???");
-               errors++;
-       }
 
        if (state.got_basic_prompt) {
                debug_printf (1, " BASIC_PROMPT");
-               if (!get_basic_prompt) {
+               if (!get_basic_prompt)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (get_basic_prompt) {
+       } else if (get_basic_prompt)
                debug_printf (1, " no-basic-prompt???");
-               errors++;
-       }
 
        if (state.sent_ntlm_request) {
                debug_printf (1, " REQUEST");
-               if (!do_ntlm) {
+               if (!do_ntlm)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (do_ntlm) {
+       } else if (do_ntlm)
                debug_printf (1, " no-request???");
-               errors++;
-       }
 
        if (state.got_ntlm_challenge) {
                debug_printf (1, " CHALLENGE");
-               if (!do_ntlm) {
+               if (!do_ntlm)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (do_ntlm) {
+       } else if (do_ntlm)
                debug_printf (1, " no-challenge???");
-               errors++;
-       }
 
        if (state.sent_ntlm_response) {
                debug_printf (1, " NTLM_RESPONSE");
-               if (!do_ntlm) {
+               if (!do_ntlm)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (do_ntlm) {
+       } else if (do_ntlm)
                debug_printf (1, " no-ntlm-response???");
-               errors++;
-       }
 
        if (state.sent_basic_response) {
                debug_printf (1, " BASIC_RESPONSE");
-               if (!do_basic) {
+               if (!do_basic)
                        debug_printf (1, "???");
-                       errors++;
-               }
-       } else if (do_basic) {
+       } else if (do_basic)
                debug_printf (1, " no-basic-response???");
-               errors++;
-       }
 
        debug_printf (1, " -> %s", msg->reason_phrase);
-       if (msg->status_code != status_code) {
+       if (msg->status_code != status_code)
                debug_printf (1, "???");
-               errors++;
-       }
        debug_printf (1, "\n");
 
+       g_assert_true (state.got_ntlm_prompt == get_ntlm_prompt);
+       g_assert_true (state.got_basic_prompt == get_basic_prompt);
+       g_assert_true (state.sent_ntlm_request == do_ntlm);
+       g_assert_true (state.got_ntlm_challenge == do_ntlm);
+       g_assert_true (state.sent_ntlm_response == do_ntlm);
+       g_assert_true (state.sent_basic_response == do_basic);
+       soup_test_assert_message_status (msg, status_code);
+
        g_object_unref (msg);
 }
 
@@ -363,12 +345,10 @@ do_ntlm_round (SoupURI *base_uri, gboolean use_ntlm,
                    FALSE, FALSE,
                    SOUP_STATUS_OK);
 
-       if (authenticated_ntlm != (use_ntlm && use_builtin_ntlm)) {
-               debug_printf (1, "  ERROR: %s built-in NTLM support, but authenticate signal %s emitted\n",
-                             use_builtin_ntlm ? "Using" : "Not using",
-                             authenticated_ntlm ? "was" : "wasn't");
-               errors++;
-       }
+       soup_test_assert (authenticated_ntlm == (use_ntlm && use_builtin_ntlm),
+                         "%s built-in NTLM support, but authenticate signal %s emitted\n",
+                         use_builtin_ntlm ? "Using" : "Not using",
+                         authenticated_ntlm ? "was" : "wasn't");
 
        /* 2. Server requires auth as Alice, so it will request that
         * if we didn't already authenticate the connection to her in
@@ -464,6 +444,48 @@ do_ntlm_tests (SoupURI *base_uri, gboolean use_builtin_ntlm)
 }
 
 static void
+do_builtin_ntlm_test (gconstpointer data)
+{
+       SoupURI *uri = (SoupURI *)data;
+
+       /* Built-in NTLM auth support. (We set SOUP_NTLM_AUTH_DEBUG to
+        * an empty string to ensure that the built-in support is
+        * being used, even if /usr/bin/ntlm_auth is available.)
+        */
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG", "", TRUE);
+       do_ntlm_tests (uri, TRUE);
+}
+
+#ifdef USE_NTLM_AUTH
+static void
+do_winbind_ntlm_test (gconstpointer data)
+{
+       SoupURI *uri = (SoupURI *)data;
+
+       /* Samba winbind /usr/bin/ntlm_auth helper support (via a
+        * helper program that emulates its interface).
+        */
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG", BUILDDIR "/ntlm-test-helper", TRUE);
+       g_unsetenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS");
+       do_ntlm_tests (uri, FALSE);
+}
+
+static void
+do_fallback_ntlm_test (gconstpointer data)
+{
+       SoupURI *uri = (SoupURI *)data;
+
+       /* Support for when ntlm_auth is installed, but the user has
+        * no cached credentials (and thus we have to fall back to
+        * libsoup's built-in NTLM support).
+        */
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG", BUILDDIR "/ntlm-test-helper", TRUE);
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS", "1", TRUE);
+       do_ntlm_tests (uri, TRUE);
+}
+#endif
+
+static void
 retry_test_authenticate (SoupSession *session, SoupMessage *msg,
                         SoupAuth *auth, gboolean retrying,
                         gpointer user_data)
@@ -483,13 +505,16 @@ retry_test_authenticate (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-do_retrying_test (SoupURI *base_uri)
+do_retrying_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupMessage *msg;
        SoupURI *uri;
        gboolean retried = FALSE;
 
+       g_setenv ("SOUP_NTLM_AUTH_DEBUG", "", TRUE);
+
        debug_printf (1, "  /alice\n");
 
        session = soup_test_session_new (SOUP_TYPE_SESSION,
@@ -504,15 +529,9 @@ do_retrying_test (SoupURI *base_uri)
 
        soup_session_send_message (session, msg);
 
-       if (!retried) {
-               debug_printf (1, "    Didn't retry!\n");
-               errors++;
-       }
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    Unexpected final status %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       g_assert_true (retried);
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -532,15 +551,9 @@ do_retrying_test (SoupURI *base_uri)
 
        soup_session_send_message (session, msg);
 
-       if (!retried) {
-               debug_printf (1, "    Didn't retry!\n");
-               errors++;
-       }
-       if (msg->status_code != SOUP_STATUS_UNAUTHORIZED) {
-               debug_printf (1, "    Unexpected final status %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       g_assert_true (retried);
+       soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
+
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -552,6 +565,7 @@ main (int argc, char **argv)
        SoupServer *server;
        GHashTable *connections;
        SoupURI *uri;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -563,35 +577,14 @@ main (int argc, char **argv)
        uri = soup_uri_new ("http://127.0.0.1/";);
        soup_uri_set_port (uri, soup_server_get_port (server));
 
-       /* Built-in NTLM auth support. (We set SOUP_NTLM_AUTH_DEBUG to
-        * an empty string to ensure that the built-in support is
-        * being used, even if /usr/bin/ntlm_auth is available.)
-        */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG", "", TRUE);
-       debug_printf (1, "Built-in NTLM support\n");
-       do_ntlm_tests (uri, TRUE);
-
+       g_test_add_data_func ("/ntlm/builtin", uri, do_builtin_ntlm_test);
 #ifdef USE_NTLM_AUTH
-       /* Samba winbind /usr/bin/ntlm_auth helper support (via a
-        * helper program that emulates its interface).
-        */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG", BUILDDIR "/ntlm-test-helper", TRUE);
-       debug_printf (1, "\nExternal helper support\n");
-       do_ntlm_tests (uri, FALSE);
-
-       /* Support for when ntlm_auth is installed, but the user has
-        * no cached credentials (and thus we have to fall back to
-        * libsoup's built-in NTLM support).
-        */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG_NOCREDS", "1", TRUE);
-       debug_printf (1, "\nExternal -> fallback support\n");
-       do_ntlm_tests (uri, TRUE);
+       g_test_add_data_func ("/ntlm/winbind", uri, do_winbind_ntlm_test);
+       g_test_add_data_func ("/ntlm/fallback", uri, do_fallback_ntlm_test);
 #endif
+       g_test_add_data_func ("/ntlm/retry", uri, do_retrying_test);
 
-       /* Other tests */
-       g_setenv ("SOUP_NTLM_AUTH_DEBUG", "", TRUE);
-       debug_printf (1, "\nRetrying on failed password\n");
-       do_retrying_test (uri);
+       ret = g_test_run ();
 
        soup_uri_free (uri);
 
@@ -599,5 +592,5 @@ main (int argc, char **argv)
        test_cleanup ();
        g_hash_table_destroy (connections);
 
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/proxy-test.c b/tests/proxy-test.c
index 682b537..ceb2ff3 100644
--- a/tests/proxy-test.c
+++ b/tests/proxy-test.c
@@ -46,19 +46,15 @@ authenticate (SoupSession *session, SoupMessage *msg,
              SoupAuth *auth, gboolean retrying, gpointer data)
 {
        if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
-               if (soup_auth_is_for_proxy (auth)) {
-                       debug_printf (1, "  got proxy auth object for 401!\n");
-                       errors++;
-               }
+               soup_test_assert (!soup_auth_is_for_proxy (auth),
+                                 "got proxy auth object for 401");
        } else if (msg->status_code == SOUP_STATUS_PROXY_UNAUTHORIZED) {
-               if (!soup_auth_is_for_proxy (auth)) {
-                       debug_printf (1, "  got regular auth object for 407!\n");
-                       errors++;
-               }
+               soup_test_assert (soup_auth_is_for_proxy (auth),
+                                 "got regular auth object for 407");
        } else {
-               debug_printf (1, "  got authenticate signal with status %d\n",
-                             msg->status_code);
-               errors++;
+               soup_test_assert (FALSE,
+                                 "got authenticate signal with status %d\n",
+                                 msg->status_code);
        }
 
        if (!retrying)
@@ -120,10 +116,7 @@ test_url (const char *url, int proxy, guint expected,
        soup_session_send_message (session, msg);
 
        debug_printf (1, "  %d %s\n", msg->status_code, msg->reason_phrase);
-       if (msg->status_code != expected) {
-               debug_printf (1, "  EXPECTED %d!\n", expected);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, expected);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
@@ -168,29 +161,18 @@ test_url_new_api (const char *url, int proxy, guint expected,
        msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (request));
 
        stream = soup_test_request_send (request, NULL, 0, &error);
-       if (!stream) {
-               debug_printf (1, "  Unexpected error on Request: %s\n",
-                             error->message);
-               errors++;
-               g_clear_error (&error);
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
        if (stream) {
-               soup_test_request_close_stream (request, stream, NULL, NULL);
-               if (error) {
-                       debug_printf (1, "  Unexpected error on close: %s\n",
-                                     error->message);
-                       errors++;
-                       g_clear_error (&error);
-               }
+               soup_test_request_close_stream (request, stream, NULL, &error);
+               g_assert_no_error (error);
+               g_clear_error (&error);
                g_object_unref (stream);
        }
 
        debug_printf (1, "  %d %s\n", msg->status_code, msg->reason_phrase);
-       if (msg->status_code != expected) {
-               debug_printf (1, "  EXPECTED %d!\n", expected);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, expected);
 
        g_object_unref (msg);
        g_object_unref (request);
@@ -199,20 +181,17 @@ test_url_new_api (const char *url, int proxy, guint expected,
 }
 
 static void
-run_test (int i, gboolean sync)
+do_proxy_test (SoupProxyTest *test, gboolean sync)
 {
        char *http_url, *https_url;
 
-       debug_printf (1, "Test %d: %s (%s)\n", i + 1, tests[i].explanation,
-                     sync ? "sync" : "async");
-
-       if (!strncmp (tests[i].url, "http", 4)) {
+       if (!strncmp (test->url, "http", 4)) {
                SoupURI *uri;
                guint port;
 
-               http_url = g_strdup (tests[i].url);
+               http_url = g_strdup (test->url);
 
-               uri = soup_uri_new (tests[i].url);
+               uri = soup_uri_new (test->url);
                port = uri->port;
                soup_uri_set_scheme (uri, "https");
                if (port)
@@ -220,26 +199,26 @@ run_test (int i, gboolean sync)
                https_url = soup_uri_to_string (uri, FALSE);
                soup_uri_free (uri);
        } else {
-               http_url = g_strconcat (HTTP_SERVER, tests[i].url, NULL);
-               https_url = g_strconcat (HTTPS_SERVER, tests[i].url, NULL);
+               http_url = g_strconcat (HTTP_SERVER, test->url, NULL);
+               https_url = g_strconcat (HTTPS_SERVER, test->url, NULL);
        }
 
-       test_url (http_url, SIMPLE_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (http_url, SIMPLE_PROXY, tests[i].final_status, sync, FALSE);
-       test_url (https_url, SIMPLE_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (https_url, SIMPLE_PROXY, tests[i].final_status, sync, FALSE);
+       test_url (http_url, SIMPLE_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (http_url, SIMPLE_PROXY, test->final_status, sync, FALSE);
+       test_url (https_url, SIMPLE_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (https_url, SIMPLE_PROXY, test->final_status, sync, FALSE);
 
-       test_url (http_url, AUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (http_url, AUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url (https_url, AUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (https_url, AUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url (https_url, AUTH_PROXY, tests[i].final_status, sync, TRUE);
-       test_url_new_api (https_url, AUTH_PROXY, tests[i].final_status, sync, TRUE);
+       test_url (http_url, AUTH_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (http_url, AUTH_PROXY, test->final_status, sync, FALSE);
+       test_url (https_url, AUTH_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (https_url, AUTH_PROXY, test->final_status, sync, FALSE);
+       test_url (https_url, AUTH_PROXY, test->final_status, sync, TRUE);
+       test_url_new_api (https_url, AUTH_PROXY, test->final_status, sync, TRUE);
 
-       test_url (http_url, UNAUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (http_url, UNAUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url (https_url, UNAUTH_PROXY, tests[i].final_status, sync, FALSE);
-       test_url_new_api (https_url, UNAUTH_PROXY, tests[i].final_status, sync, FALSE);
+       test_url (http_url, UNAUTH_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (http_url, UNAUTH_PROXY, test->final_status, sync, FALSE);
+       test_url (https_url, UNAUTH_PROXY, test->final_status, sync, FALSE);
+       test_url_new_api (https_url, UNAUTH_PROXY, test->final_status, sync, FALSE);
 
        g_free (http_url);
        g_free (https_url);
@@ -247,61 +226,20 @@ run_test (int i, gboolean sync)
        debug_printf (1, "\n");
 }
 
-static gpointer
-async_proxy_test_thread (gpointer num)
+static void
+do_async_proxy_test (gconstpointer data)
 {
-       GMainContext *context = g_main_context_new ();
-
-       g_main_context_push_thread_default (context);
-       run_test (GPOINTER_TO_INT (num), FALSE);
-       g_main_context_pop_thread_default (context);
-       g_main_context_unref (context);
+       SoupProxyTest *test = (SoupProxyTest *)data;
 
-       return NULL;
-}
-
-static gpointer
-sync_proxy_test_thread (gpointer num)
-{
-       run_test (GPOINTER_TO_INT (num), TRUE);
-       return NULL;
+       do_proxy_test (test, FALSE);
 }
 
 static void
-do_proxy_tests (void)
+do_sync_proxy_test (gconstpointer data)
 {
-       int i;
-
-       debug_printf (1, "Basic proxy tests\n");
-
-       if (parallelize) {
-               GThread *threads[ntests];
-
-               /* Doing the sync and async tests separately is faster
-                * than doing them both at the same time (hitting
-                * apache's connection limit maybe?)
-                */
-               for (i = 0; i < ntests; i++) {
-                       threads[i] = g_thread_new ("async_proxy_test",
-                                                  async_proxy_test_thread,
-                                                  GINT_TO_POINTER (i));
-               }
-               for (i = 0; i < ntests; i++)
-                       g_thread_join (threads[i]);
-
-               for (i = 0; i < ntests; i++) {
-                       threads[i] = g_thread_new ("sync_proxy_test",
-                                                  sync_proxy_test_thread,
-                                                  GINT_TO_POINTER (i));
-               }
-               for (i = 0; i < ntests; i++)
-                       g_thread_join (threads[i]);
-       } else {
-               for (i = 0; i < ntests; i++) {
-                       run_test (i, FALSE);
-                       run_test (i, TRUE);
-               }
-       }
+       SoupProxyTest *test = (SoupProxyTest *)data;
+
+       do_proxy_test (test, TRUE);
 }
 
 static void
@@ -315,8 +253,9 @@ server_callback (SoupServer *server, SoupMessage *msg,
 }
 
 static void
-do_proxy_fragment_test (SoupURI *base_uri)
+do_proxy_fragment_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
        SoupURI *proxy_uri, *req_uri;
        SoupMessage *msg;
@@ -334,11 +273,7 @@ do_proxy_fragment_test (SoupURI *base_uri)
        soup_uri_free (req_uri);
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  unexpected status %d %s!\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
@@ -370,17 +305,11 @@ do_proxy_redirect_test (void)
        soup_session_send_message (session, msg);
 
        new_uri = soup_message_get_uri (msg);
-       if (!strcmp (req_uri->path, new_uri->path)) {
-               debug_printf (1, "  message was not redirected!\n");
-               errors++;
-       }
+       soup_test_assert (strcmp (req_uri->path, new_uri->path) != 0,
+                         "message was not redirected");
        soup_uri_free (req_uri);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  unexpected status %d %s!\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        g_object_unref (msg);
        soup_test_session_abort_unref (session);
@@ -391,7 +320,8 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        SoupURI *base_uri;
-       int i;
+       char *path;
+       int i, ret;
 
        test_init (argc, argv, NULL);
        apache_init ();
@@ -406,15 +336,27 @@ main (int argc, char **argv)
        base_uri = soup_uri_new ("http://127.0.0.1/";);
        soup_uri_set_port (base_uri, soup_server_get_port (server));
 
-       do_proxy_tests ();
-       do_proxy_fragment_test (base_uri);
-       do_proxy_redirect_test ();
+       for (i = 0; i < ntests; i++) {
+               path = g_strdup_printf ("/proxy/async/%s", tests[i].explanation);
+               g_test_add_data_func (path, &tests[i], do_async_proxy_test);
+               g_free (path);
+       }
+       for (i = 0; i < ntests; i++) {
+               path = g_strdup_printf ("/proxy/sync/%s", tests[i].explanation);
+               g_test_add_data_func (path, &tests[i], do_sync_proxy_test);
+               g_free (path);
+       }
+
+       g_test_add_data_func ("/proxy/fragment", base_uri, do_proxy_fragment_test);
+       g_test_add_func ("/proxy/redirect", do_proxy_redirect_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_APACHE */
diff --git a/tests/pull-api.c b/tests/pull-api.c
index 070c209..8060646 100644
--- a/tests/pull-api.c
+++ b/tests/pull-api.c
@@ -163,9 +163,7 @@ fully_async_got_headers (SoupMessage *msg, gpointer user_data)
                 */
                return;
        } else if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "  unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
+               soup_test_assert_message_status (msg, SOUP_STATUS_OK);
                return;
        }
 
@@ -194,18 +192,10 @@ fully_async_got_chunk (SoupMessage *msg, SoupBuffer *chunk, gpointer user_data)
         * test program, that means comparing it against
         * correct_response to make sure that we got the right data.
         */
-       if (ad->read_so_far + chunk->length > correct_response->length) {
-               debug_printf (1, "  read too far! (%lu > %lu)\n",
-                             (unsigned long) (ad->read_so_far + chunk->length),
-                             (unsigned long) correct_response->length);
-               errors++;
-       } else if (memcmp (chunk->data,
-                          correct_response->data + ad->read_so_far,
-                          chunk->length) != 0) {
-               debug_printf (1, "  data mismatch in block starting at %lu\n",
-                             (unsigned long) ad->read_so_far);
-               errors++;
-       }
+       g_assert_cmpint (ad->read_so_far + chunk->length, <=, correct_response->length);
+       soup_assert_cmpmem (chunk->data, chunk->length,
+                           correct_response->data + ad->read_so_far,
+                           chunk->length);
        ad->read_so_far += chunk->length;
 
        /* Now pause I/O, and prepare to read another chunk later.
@@ -226,11 +216,7 @@ fully_async_finished (SoupSession *session, SoupMessage *msg,
 {
        FullyAsyncData *ad = user_data;
 
-       if (msg->status_code != ad->expected_status) {
-               debug_printf (1, "  unexpected final status: %d %s !\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, ad->expected_status);
 
        if (ad->timeout != 0)
                g_source_remove (ad->timeout);
@@ -242,6 +228,41 @@ fully_async_finished (SoupSession *session, SoupMessage *msg,
        g_main_loop_quit (ad->loop);
 }
 
+static void
+do_fast_async_test (gconstpointer data)
+{
+       const char *base_uri = data;
+       SoupSession *session;
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+       g_signal_connect (session, "authenticate",
+                         G_CALLBACK (authenticate), NULL);
+       do_fully_async_test (session, base_uri, "/",
+                            TRUE, SOUP_STATUS_OK);
+       do_fully_async_test (session, base_uri, "/Basic/realm1/",
+                            TRUE, SOUP_STATUS_UNAUTHORIZED);
+       do_fully_async_test (session, base_uri, "/Basic/realm2/",
+                            TRUE, SOUP_STATUS_OK);
+       soup_test_session_abort_unref (session);
+}
+
+static void
+do_slow_async_test (gconstpointer data)
+{
+       const char *base_uri = data;
+       SoupSession *session;
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+       g_signal_connect (session, "authenticate",
+                         G_CALLBACK (authenticate), NULL);
+       do_fully_async_test (session, base_uri, "/",
+                            FALSE, SOUP_STATUS_OK);
+       do_fully_async_test (session, base_uri, "/Basic/realm1/",
+                            FALSE, SOUP_STATUS_UNAUTHORIZED);
+       do_fully_async_test (session, base_uri, "/Basic/realm2/",
+                            FALSE, SOUP_STATUS_OK);
+       soup_test_session_abort_unref (session);
+}
 
 /* Pull API version 2: synchronous pull API via async I/O. */
 
@@ -286,14 +307,12 @@ do_synchronously_async_test (SoupSession *session,
 
        /* Send the message, get back headers */
        sync_async_send (session, msg);
-       if (sync_async_is_finished (msg) &&
-           expected_status == SOUP_STATUS_OK) {
-               debug_printf (1, "  finished without reading response!\n");
-               errors++;
-       } else if (!sync_async_is_finished (msg) &&
-                  expected_status != SOUP_STATUS_OK) {
-               debug_printf (1, "  request failed to fail!\n");
-               errors++;
+       if (expected_status == SOUP_STATUS_OK) {
+               soup_test_assert (!sync_async_is_finished (msg),
+                                 "finished without reading response");
+       } else {
+               soup_test_assert (sync_async_is_finished (msg),
+                                 "request failed to fail");
        }
 
        /* Now we're ready to read the response body (though we could
@@ -305,32 +324,19 @@ do_synchronously_async_test (SoupSession *session,
                              (unsigned long) read_so_far,
                              (unsigned long) read_so_far + chunk->length);
 
-               if (read_so_far + chunk->length > correct_response->length) {
-                       debug_printf (1, "  read too far! (%lu > %lu)\n",
-                                     (unsigned long) read_so_far + chunk->length,
-                                     (unsigned long) correct_response->length);
-                       errors++;
-               } else if (memcmp (chunk->data,
-                                  correct_response->data + read_so_far,
-                                  chunk->length) != 0) {
-                       debug_printf (1, "  data mismatch in block starting at %lu\n",
-                                     (unsigned long) read_so_far);
-                       errors++;
-               }
+               g_assert_cmpint (read_so_far + chunk->length, <=, correct_response->length);
+               soup_assert_cmpmem (chunk->data, chunk->length,
+                                   correct_response->data + read_so_far,
+                                   chunk->length);
+
                read_so_far += chunk->length;
                soup_buffer_free (chunk);
        }
 
-       if (!sync_async_is_finished (msg) ||
-           (msg->status_code == SOUP_STATUS_OK &&
-            read_so_far != correct_response->length)) {
-               debug_printf (1, "  loop ended before message was fully read!\n");
-               errors++;
-       } else if (msg->status_code != expected_status) {
-               debug_printf (1, "  unexpected final status: %d %s !\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       g_assert_true (sync_async_is_finished (msg));
+       soup_test_assert_message_status (msg, expected_status);
+       if (msg->status_code == SOUP_STATUS_OK)
+               g_assert_cmpint (read_so_far, ==, correct_response->length);
 
        sync_async_cleanup (msg);
        g_object_unref (msg);
@@ -395,9 +401,7 @@ sync_async_got_headers (SoupMessage *msg, gpointer user_data)
                 */
                return;
        } else if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "  unexpected status: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
+               soup_test_assert_message_status (msg, SOUP_STATUS_OK);
                return;
        }
 
@@ -475,44 +479,12 @@ sync_async_cleanup (SoupMessage *msg)
        g_free (ad);
 }
 
-
-int
-main (int argc, char **argv)
+static void
+do_sync_async_test (gconstpointer data)
 {
+       const char *base_uri = data;
        SoupSession *session;
-       const char *base_uri;
 
-       test_init (argc, argv, NULL);
-       apache_init ();
-
-       base_uri = "http://127.0.0.1:47524/";;
-       get_correct_response (base_uri);
-
-       debug_printf (1, "\nFully async, fast requests\n");
-       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       g_signal_connect (session, "authenticate",
-                         G_CALLBACK (authenticate), NULL);
-       do_fully_async_test (session, base_uri, "/",
-                            TRUE, SOUP_STATUS_OK);
-       do_fully_async_test (session, base_uri, "/Basic/realm1/",
-                            TRUE, SOUP_STATUS_UNAUTHORIZED);
-       do_fully_async_test (session, base_uri, "/Basic/realm2/",
-                            TRUE, SOUP_STATUS_OK);
-       soup_test_session_abort_unref (session);
-
-       debug_printf (1, "\nFully async, slow requests\n");
-       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       g_signal_connect (session, "authenticate",
-                         G_CALLBACK (authenticate), NULL);
-       do_fully_async_test (session, base_uri, "/",
-                            FALSE, SOUP_STATUS_OK);
-       do_fully_async_test (session, base_uri, "/Basic/realm1/",
-                            FALSE, SOUP_STATUS_UNAUTHORIZED);
-       do_fully_async_test (session, base_uri, "/Basic/realm2/",
-                            FALSE, SOUP_STATUS_OK);
-       soup_test_session_abort_unref (session);
-
-       debug_printf (1, "\nSynchronously async\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
        g_signal_connect (session, "authenticate",
                          G_CALLBACK (authenticate), NULL);
@@ -523,11 +495,31 @@ main (int argc, char **argv)
        do_synchronously_async_test (session, base_uri, "/Basic/realm2/",
                                     SOUP_STATUS_OK);
        soup_test_session_abort_unref (session);
+}
+
+
+int
+main (int argc, char **argv)
+{
+       const char *base_uri;
+       int ret;
+
+       test_init (argc, argv, NULL);
+       apache_init ();
+
+       base_uri = "http://127.0.0.1:47524/";;
+       get_correct_response (base_uri);
+
+       g_test_add_data_func ("/pull-api/async/fast", base_uri, do_fast_async_test);
+       g_test_add_data_func ("/pull-api/async/slow", base_uri, do_slow_async_test);
+       g_test_add_data_func ("/pull-api/sync-async", base_uri, do_sync_async_test);
+
+       ret = g_test_run ();
 
        soup_buffer_free (correct_response);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_APACHE */
diff --git a/tests/range-test.c b/tests/range-test.c
index 00b8567..89ae59c 100644
--- a/tests/range-test.c
+++ b/tests/range-test.c
@@ -35,41 +35,39 @@ check_part (SoupMessageHeaders *headers, const char *body, gsize body_len,
                      soup_message_headers_get_one (headers, "Content-Range"));
 
        if (!soup_message_headers_get_content_range (headers, &start, &end, &total_length)) {
-               debug_printf (1, "    Could not find/parse Content-Range\n");
-               errors++;
+               soup_test_assert (FALSE, "Could not find/parse Content-Range");
                return;
        }
 
        if (total_length != full_response->length && total_length != -1) {
-               debug_printf (1, "    Unexpected total length %" G_GINT64_FORMAT " in response\n",
-                             total_length);
-               errors++;
+               soup_test_assert (FALSE,
+                                 "Unexpected total length %" G_GINT64_FORMAT " in response\n",
+                                 total_length);
                return;
        }
 
        if (check_start_end) {
                if ((expected_start >= 0 && start != expected_start) ||
                    (expected_start < 0 && start != full_response->length + expected_start)) {
-                       debug_printf (1, "    Unexpected range start %" G_GINT64_FORMAT " in response\n",
-                                     start);
-                       errors++;
+                       soup_test_assert (FALSE,
+                                         "Unexpected range start %" G_GINT64_FORMAT " in response\n",
+                                         start);
                        return;
                }
 
                if ((expected_end >= 0 && end != expected_end) ||
                    (expected_end < 0 && end != full_response->length - 1)) {
-                       debug_printf (1, "    Unexpected range end %" G_GINT64_FORMAT " in response\n",
-                                     end);
-                       errors++;
+                       soup_test_assert (FALSE,
+                                         "Unexpected range end %" G_GINT64_FORMAT " in response\n",
+                                         end);
                        return;
                }
        }
 
        if (end - start + 1 != body_len) {
-               debug_printf (1, "    Range length (%d) does not match body length (%d)\n",
-                             (int)(end - start) + 1,
-                             (int)body_len);
-               errors++;
+               soup_test_assert (FALSE, "Range length (%d) does not match body length (%d)\n",
+                                 (int)(end - start) + 1,
+                                 (int)body_len);
                return;
        }
 
@@ -87,42 +85,26 @@ do_single_range (SoupSession *session, SoupMessage *msg,
 
        soup_session_send_message (session, msg);
 
-       if (succeed) {
-               if (msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
-                       debug_printf (1, "    Unexpected status %d %s\n",
-                                     msg->status_code, msg->reason_phrase);
-                       g_object_unref (msg);
-                       errors++;
-                       return;
-               }
-       } else {
-               if (msg->status_code == SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) {
-                       debug_printf (1, "    Got expected %d %s\n",
-                                     msg->status_code, msg->reason_phrase);
-               } else {
+       if (!succeed) {
+               soup_test_assert_message_status (msg, SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE);
+               if (msg->status_code != SOUP_STATUS_REQUESTED_RANGE_NOT_SATISFIABLE) {
                        const char *content_range;
 
-                       debug_printf (1, "    Unexpected status %d %s\n",
-                                     msg->status_code, msg->reason_phrase);
                        content_range = soup_message_headers_get_one (msg->response_headers,
                                                                      "Content-Range");
                        if (content_range)
                                debug_printf (1, "    Content-Range: %s\n", content_range);
-                       errors++;
                }
 
                g_object_unref (msg);
                return;
        }
 
+       soup_test_assert_message_status (msg, SOUP_STATUS_PARTIAL_CONTENT);
+
        content_type = soup_message_headers_get_content_type (
                msg->response_headers, NULL);
-       if (content_type && !strcmp (content_type, "multipart/byteranges")) {
-               debug_printf (1, "    Response body should not have been multipart/byteranges\n");
-               g_object_unref (msg);
-               errors++;
-               return;
-       }
+       g_assert_cmpstr (content_type, !=, "multipart/byteranges");
 
        check_part (msg->response_headers, msg->response_body->data,
                    msg->response_body->length, TRUE, start, end);
@@ -153,38 +135,21 @@ do_multi_range (SoupSession *session, SoupMessage *msg,
 
        soup_session_send_message (session, msg);
 
-       if (msg->status_code != SOUP_STATUS_PARTIAL_CONTENT) {
-               debug_printf (1, "    Unexpected status %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               g_object_unref (msg);
-               errors++;
-               return;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_PARTIAL_CONTENT);
 
        content_type = soup_message_headers_get_content_type (msg->response_headers, NULL);
-       if (!content_type || strcmp (content_type, "multipart/byteranges") != 0) {
-               debug_printf (1, "    Response Content-Type (%s) was not multipart/byteranges\n",
-                             content_type);
-               g_object_unref (msg);
-               errors++;
-               return;
-       }
+       g_assert_cmpstr (content_type, ==, "multipart/byteranges");
 
        multipart = soup_multipart_new_from_message (msg->response_headers,
                                                     msg->response_body);
        if (!multipart) {
-               debug_printf (1, "    Could not parse multipart\n");
+               soup_test_assert (FALSE, "Could not parse multipart");
                g_object_unref (msg);
-               errors++;
                return;
        }
 
        length = soup_multipart_get_length (multipart);
-       if (length != expected_return_ranges) {
-               debug_printf (1, "    Expected %d ranges, got %d\n",
-                             expected_return_ranges, length);
-               errors++;
-       }
+       g_assert_cmpint (length, ==, expected_return_ranges);
 
        for (i = 0; i < length; i++) {
                SoupMessageHeaders *headers;
@@ -360,10 +325,8 @@ do_range_test (SoupSession *session, const char *uri,
                              10 * twelfths - 5, 11 * twelfths,
                              expect_partial_coalesce ? 2 : 3);
 
-       if (memcmp (full_response->data, test_response, full_response->length) != 0) {
-               debug_printf (1, "\nfull_response and test_response don't match\n");
-               errors++;
-       }
+       soup_assert_cmpmem (full_response->data, full_response->length,
+                           test_response, full_response->length);
 
        debug_printf (1, "Requesting (invalid) %d-%d\n",
                      (int) full_response->length + 1,
@@ -382,6 +345,22 @@ do_range_test (SoupSession *session, const char *uri,
 }
 
 static void
+do_apache_range_test (void)
+{
+       SoupSession *session;
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
+
+#if HAVE_APACHE_2_2
+       do_range_test (session, "http://127.0.0.1:47524/";, FALSE, FALSE);
+#else
+       do_range_test (session, "http://127.0.0.1:47524/";, TRUE, FALSE);
+#endif
+
+       soup_test_session_abort_unref (session);
+}
+
+static void
 server_handler (SoupServer        *server,
                SoupMessage       *msg, 
                const char        *path,
@@ -394,29 +373,15 @@ server_handler (SoupServer        *server,
                                         full_response);
 }
 
-int
-main (int argc, char **argv)
+static void
+do_libsoup_range_test (void)
 {
        SoupSession *session;
        SoupServer *server;
        char *base_uri;
 
-       test_init (argc, argv, NULL);
-       apache_init ();
-
-       get_full_response ();
-       test_response = g_malloc0 (full_response->length);
-
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
 
-       debug_printf (1, "1. Testing against apache\n");
-#if HAVE_APACHE_2_2
-       do_range_test (session, "http://127.0.0.1:47524/";, FALSE, FALSE);
-#else
-       do_range_test (session, "http://127.0.0.1:47524/";, TRUE, FALSE);
-#endif
-
-       debug_printf (1, "\n2. Testing against SoupServer\n");
        server = soup_test_server_new (FALSE);
        soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
        base_uri = g_strdup_printf ("http://127.0.0.1:%u/";,
@@ -426,12 +391,29 @@ main (int argc, char **argv)
        soup_test_server_quit_unref (server);
 
        soup_test_session_abort_unref (session);
+}
+
+int
+main (int argc, char **argv)
+{
+       int ret;
+
+       test_init (argc, argv, NULL);
+       apache_init ();
+
+       get_full_response ();
+       test_response = g_malloc0 (full_response->length);
+
+       g_test_add_func ("/ranges/apache", do_apache_range_test);
+       g_test_add_func ("/ranges/libsoup", do_libsoup_range_test);
+
+       ret = g_test_run ();
 
        soup_buffer_free (full_response);
        g_free (test_response);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_APACHE */
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index 2b4fb5e..b20a318 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -5,7 +5,9 @@
 
 #include "test-utils.h"
 
+SoupURI *base_uri;
 char *server2_uri;
+SoupSession *async_session, *sync_session;
 
 typedef struct {
        const char *method;
@@ -14,11 +16,13 @@ typedef struct {
        gboolean repeat;
 } TestRequest;
 
-static struct {
+typedef struct {
        TestRequest requests[3];
        guint final_status;
        guint request_api_final_status;
-} tests[] = {
+} TestCase;
+
+static TestCase tests[] = {
        /* A redirecty response to a GET or HEAD should cause a redirect */
 
        { { { "GET", "/301", 301 },
@@ -131,11 +135,7 @@ got_headers (SoupMessage *msg, gpointer user_data)
        if (!(*treq)->method)
                return;
 
-       if (msg->status_code != (*treq)->status_code) {
-               debug_printf (1, "    - Expected %d !\n",
-                             (*treq)->status_code);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, (*treq)->status_code);
 }
 
 static void
@@ -149,35 +149,26 @@ restarted (SoupMessage *msg, gpointer user_data)
        if ((*treq)->method && !(*treq)->repeat)
                (*treq)++;
 
-       if (!(*treq)->method) {
-               debug_printf (1, "    - Expected to be done!\n");
-               errors++;
-               return;
-       }
+       soup_test_assert ((*treq)->method,
+                         "Expected to be done");
 
-       if (strcmp (msg->method, (*treq)->method) != 0) {
-               debug_printf (1, "    - Expected %s !\n", (*treq)->method);
-               errors++;
-       }
-       if (strcmp (uri->path, (*treq)->path) != 0) {
-               debug_printf (1, "    - Expected %s !\n", (*treq)->path);
-               errors++;
-       }
+       g_assert_cmpstr (msg->method, ==, (*treq)->method);
+       g_assert_cmpstr (uri->path, ==, (*treq)->path);
 }
 
 static void
-do_message_api_test (SoupSession *session, SoupURI *base_uri, int n)
+do_message_api_test (SoupSession *session, TestCase *test)
 {
        SoupURI *uri;
        SoupMessage *msg;
        TestRequest *treq;
 
-       debug_printf (1, "%2d. %s %s\n", n + 1,
-                     tests[n].requests[0].method,
-                     tests[n].requests[0].path);
+       debug_printf (1, "%s %s\n",
+                     test->requests[0].method,
+                     test->requests[0].path);
 
-       uri = soup_uri_new_with_base (base_uri, tests[n].requests[0].path);
-       msg = soup_message_new_from_uri (tests[n].requests[0].method, uri);
+       uri = soup_uri_new_with_base (base_uri, test->requests[0].path);
+       msg = soup_message_new_from_uri (test->requests[0].method, uri);
        soup_uri_free (uri);
 
        if (msg->method == SOUP_METHOD_POST) {
@@ -187,7 +178,7 @@ do_message_api_test (SoupSession *session, SoupURI *base_uri, int n)
                                          strlen ("post body"));
        }
 
-       treq = &tests[n].requests[0];
+       treq = &test->requests[0];
        g_signal_connect (msg, "got_headers",
                          G_CALLBACK (got_headers), &treq);
        g_signal_connect (msg, "restarted",
@@ -195,18 +186,14 @@ do_message_api_test (SoupSession *session, SoupURI *base_uri, int n)
 
        soup_session_send_message (session, msg);
 
-       if (msg->status_code != tests[n].final_status) {
-               debug_printf (1, "    - Expected final status of %d, got %d !\n",
-                             tests[n].final_status, msg->status_code);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, test->final_status);
 
        g_object_unref (msg);
        debug_printf (2, "\n");
 }
 
 static void
-do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
+do_request_api_test (SoupSession *session, TestCase *test)
 {
        SoupURI *uri;
        SoupRequestHTTP *reqh;
@@ -216,24 +203,22 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
        GError *error = NULL;
        guint final_status;
 
-       debug_printf (1, "%2d. %s %s\n", n + 1,
-                     tests[n].requests[0].method,
-                     tests[n].requests[0].path);
+       debug_printf (1, "%s %s\n",
+                     test->requests[0].method,
+                     test->requests[0].path);
 
-       final_status = tests[n].request_api_final_status;
+       final_status = test->request_api_final_status;
        if (!final_status)
-               final_status = tests[n].final_status;
+               final_status = test->final_status;
 
-       uri = soup_uri_new_with_base (base_uri, tests[n].requests[0].path);
+       uri = soup_uri_new_with_base (base_uri, test->requests[0].path);
        reqh = soup_session_request_http_uri (session,
-                                             tests[n].requests[0].method,
+                                             test->requests[0].method,
                                              uri, &error);
        soup_uri_free (uri);
-       if (!reqh) {
-               debug_printf (1, "    could not create request: %s\n",
-                             error->message);
+       g_assert_no_error (error);
+       if (error) {
                g_error_free (error);
-               errors++;
                debug_printf (2, "\n");
                return;
        }
@@ -246,7 +231,7 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
                                          strlen ("post body"));
        }
 
-       treq = &tests[n].requests[0];
+       treq = &test->requests[0];
        g_signal_connect (msg, "got_headers",
                          G_CALLBACK (got_headers), &treq);
        g_signal_connect (msg, "restarted",
@@ -255,58 +240,37 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
        stream = soup_test_request_send (SOUP_REQUEST (reqh), NULL, 0, &error);
 
        if (SOUP_STATUS_IS_TRANSPORT_ERROR (final_status)) {
-               if (stream) {
-                       debug_printf (1, "    expected failure (%s) but succeeded",
-                                     soup_status_get_phrase (final_status));
-                       errors++;
-                       g_object_unref (stream);
-               }
-               if (error->domain != SOUP_HTTP_ERROR ||
-                   error->code != final_status) {
-                       debug_printf (1, "    expected '%s' but got '%s'",
-                                     soup_status_get_phrase (final_status),
-                                     error->message);
-                       errors++;
-               }
+               g_assert_error (error, SOUP_HTTP_ERROR, final_status);
+               g_clear_error (&error);
+
+               g_assert_null (stream);
+               g_clear_object (&stream);
 
-               g_error_free (error);
                g_object_unref (msg);
                g_object_unref (reqh);
                debug_printf (2, "\n");
                return;
-       } else if (!stream) {
-               debug_printf (1, "    could not send request: %s\n",
-                             error->message);
+       }
+
+       g_assert_no_error (error);
+       if (error) {
                g_error_free (error);
                g_object_unref (msg);
                g_object_unref (reqh);
-               errors++;
                debug_printf (2, "\n");
                return;
        }
 
        soup_test_request_read_all (SOUP_REQUEST (reqh), stream, NULL, &error);
-       if (error) {
-               debug_printf (1, "    could not read from stream: %s\n",
-                             error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
        soup_test_request_close_stream (SOUP_REQUEST (reqh), stream, NULL, &error);
-       if (error) {
-               debug_printf (1, "    could not close stream: %s\n",
-                             error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (stream);
 
-       if (msg->status_code != final_status) {
-               debug_printf (1, "    - Expected final status of %d, got %d !\n",
-                             final_status, msg->status_code);
-               errors++;
-       }
+       g_assert_cmpint (msg->status_code, ==, final_status);
 
        g_object_unref (msg);
        g_object_unref (reqh);
@@ -314,30 +278,27 @@ do_request_api_test (SoupSession *session, SoupURI *base_uri, int n)
 }
 
 static void
-do_redirect_tests (SoupURI *base_uri)
+do_async_msg_api_test (gconstpointer test)
 {
-       SoupSession *session;
-       int n;
-
-       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
-                                        SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
-                                        NULL);
-       debug_printf (1, "Async session, SoupMessage\n");
-       for (n = 0; n < n_tests; n++)
-               do_message_api_test (session, base_uri, n);
-       debug_printf (1, "\nAsync session, SoupRequest\n");
-       for (n = 0; n < n_tests; n++)
-               do_request_api_test (session, base_uri, n);
-       soup_test_session_abort_unref (session);
-
-       session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
-       debug_printf (1, "\nSync session, SoupMessage\n");
-       for (n = 0; n < n_tests; n++)
-               do_message_api_test (session, base_uri, n);
-       debug_printf (1, "\nSync session, SoupRequest\n");
-       for (n = 0; n < n_tests; n++)
-               do_request_api_test (session, base_uri, n);
-       soup_test_session_abort_unref (session);
+       do_message_api_test (async_session, (TestCase *)test);
+}
+
+static void
+do_async_req_api_test (gconstpointer test)
+{
+       do_request_api_test (async_session, (TestCase *)test);
+}
+
+static void
+do_sync_msg_api_test (gconstpointer test)
+{
+       do_message_api_test (sync_session, (TestCase *)test);
+}
+
+static void
+do_sync_req_api_test (gconstpointer test)
+{
+       do_request_api_test (sync_session, (TestCase *)test);
 }
 
 typedef struct {
@@ -350,11 +311,7 @@ typedef struct {
 static void
 msg2_finished (SoupSession *session, SoupMessage *msg2, gpointer user_data)
 {
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg2->status_code)) {
-               debug_printf (1, "  msg2 failed: %d %s\n",
-                             msg2->status_code, msg2->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg2, SOUP_STATUS_OK);
 }
 
 static void
@@ -362,16 +319,12 @@ unpause_msg1 (SoupMessage *msg2, gpointer user_data)
 {
        ConnectionTestData *data = user_data;
 
-       if (!data->sock1) {
-              debug_printf (1, "  msg1 has no connection?\n");
-              errors++;
-       } else if (!data->sock2) {
-              debug_printf (1, "  msg2 has no connection?\n");
-              errors++;
-       } else if (data->sock1 == data->sock2) {
-              debug_printf (1, "  Both messages sharing the same connection\n");
-              errors++;
-       }
+       soup_test_assert (data->sock1 != NULL,
+                        "msg1 has no connection");
+       soup_test_assert (data->sock2 != NULL,
+                        "msg2 has no connection");
+       soup_test_assert (data->sock1 != data->sock2,
+                        "Both messages sharing the same connection");
 
        soup_session_unpause_message (data->session, data->msg1);
 }
@@ -422,11 +375,10 @@ request_started (SoupSession *session, SoupMessage *msg,
 }
 
 static void
-do_connection_test (SoupURI *base_uri)
+do_connection_test (void)
 {
        ConnectionTestData data;
 
-       debug_printf (1, "\nConnection reuse\n");
        memset (&data, 0, sizeof (data));
 
        data.session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
@@ -441,11 +393,8 @@ do_connection_test (SoupURI *base_uri)
                          G_CALLBACK (msg1_about_to_restart), &data);
        soup_session_send_message (data.session, data.msg1);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (data.msg1->status_code)) {
-               debug_printf (1, "  msg1 failed: %d %s\n",
-                             data.msg1->status_code, data.msg1->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (data.msg1, SOUP_STATUS_OK);
+
        g_object_unref (data.msg1);
        soup_uri_free (data.uri1);
        soup_uri_free (data.uri2);
@@ -550,29 +499,23 @@ server2_callback (SoupServer *server, SoupMessage *msg,
        soup_message_set_status (msg, SOUP_STATUS_OK);
 }
 
-static gboolean run_tests = TRUE;
-
-static GOptionEntry no_test_entry[] = {
-        { "no-tests", 'n', G_OPTION_FLAG_REVERSE,
-          G_OPTION_ARG_NONE, &run_tests,
-          "Don't run tests, just run the test server", NULL },
-        { NULL }
-};
-
 int
 main (int argc, char **argv)
 {
        GMainLoop *loop;
        SoupServer *server, *server2;
        guint port;
-       SoupURI *base_uri;
+       char *path;
+       int n, ret;
 
-       test_init (argc, argv, no_test_entry);
+       test_init (argc, argv, NULL);
 
        server = soup_test_server_new (TRUE);
        soup_server_add_handler (server, NULL,
                                 server_callback, NULL, NULL);
        port = soup_server_get_port (server);
+       base_uri = soup_uri_new ("http://127.0.0.1";);
+       soup_uri_set_port (base_uri, port);
 
        server2 = soup_test_server_new (TRUE);
        soup_server_add_handler (server2, NULL,
@@ -582,23 +525,49 @@ main (int argc, char **argv)
 
        loop = g_main_loop_new (NULL, TRUE);
 
-       if (run_tests) {
-               base_uri = soup_uri_new ("http://127.0.0.1";);
-               soup_uri_set_port (base_uri, port);
-               do_redirect_tests (base_uri);
-               do_connection_test (base_uri);
-               soup_uri_free (base_uri);
-       } else {
-               g_print ("Listening on port %d\n", port);
-               g_main_loop_run (loop);
+       async_session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
+                                              SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+                                              NULL);
+       sync_session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
+
+       for (n = 0; n < n_tests; n++) {
+               path = g_strdup_printf ("/redirect/async/msg/%d-%s-%d", n
+                                       , tests[n].requests[0].method,
+                                       tests[n].requests[0].status_code);
+               g_test_add_data_func (path, &tests[n], do_async_msg_api_test);
+               g_free (path);
+
+               path = g_strdup_printf ("/redirect/async/req/%d-%s-%d", n,
+                                       tests[n].requests[0].method,
+                                       tests[n].requests[0].status_code);
+               g_test_add_data_func (path, &tests[n], do_async_req_api_test);
+               g_free (path);
+
+               path = g_strdup_printf ("/redirect/sync/msg/%d-%s-%d", n,
+                                       tests[n].requests[0].method,
+                                       tests[n].requests[0].status_code);
+               g_test_add_data_func (path, &tests[n], do_sync_msg_api_test);
+               g_free (path);
+
+               path = g_strdup_printf ("/redirect/sync/req/%d-%s-%d", n,
+                                       tests[n].requests[0].method,
+                                       tests[n].requests[0].status_code);
+               g_test_add_data_func (path, &tests[n], do_sync_req_api_test);
+               g_free (path);
        }
 
+       g_test_add_func ("/redirect/reuse", do_connection_test);
+
+       ret = g_test_run ();
+
        g_main_loop_unref (loop);
-       g_free (server2_uri);
+       soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
+       g_free (server2_uri);
        soup_test_server_quit_unref (server2);
 
-       if (run_tests)
-               test_cleanup ();
-       return errors != 0;
+       soup_test_session_abort_unref (async_session);
+       soup_test_session_abort_unref (sync_session);
+
+       return ret;
 }
diff --git a/tests/requester-test.c b/tests/requester-test.c
index a202c16..61a69f2 100644
--- a/tests/requester-test.c
+++ b/tests/requester-test.c
@@ -123,11 +123,8 @@ stream_closed (GObject *source, GAsyncResult *res, gpointer user_data)
        GInputStream *stream = G_INPUT_STREAM (source);
        GError *error = NULL;
 
-       if (!g_input_stream_close_finish (stream, res, &error)) {
-               debug_printf (1, "    close failed: %s\n", error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_input_stream_close_finish (stream, res, &error);
+       g_assert_no_error (error);
        g_main_loop_quit (loop);
        g_object_unref (stream);
 }
@@ -143,9 +140,8 @@ test_read_ready (GObject *source, GAsyncResult *res, gpointer user_data)
 
        nread = g_input_stream_read_finish (stream, res, &error);
        if (nread == -1) {
-               debug_printf (1, "    read_async failed: %s\n", error->message);
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                g_input_stream_close (stream, NULL, NULL);
                g_object_unref (stream);
                g_main_loop_quit (loop);
@@ -174,29 +170,18 @@ auth_test_sent (GObject *source, GAsyncResult *res, gpointer user_data)
 
        stream = soup_request_send_finish (SOUP_REQUEST (source), res, &error);
        if (!stream) {
-               debug_printf (1, "    send_async failed: %s\n", error->message);
+               g_assert_no_error (error);
                g_clear_error (&error);
-               errors++;
                g_main_loop_quit (loop);
                return;
        }
 
        msg = soup_request_http_get_message (SOUP_REQUEST_HTTP (source));
-       if (msg->status_code != SOUP_STATUS_UNAUTHORIZED) {
-               debug_printf (1, "    GET failed: %d %s\n", msg->status_code,
-                             msg->reason_phrase);
-               errors++;
-               g_main_loop_quit (loop);
-               return;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED);
        g_object_unref (msg);
 
        content_type = soup_request_get_content_type (SOUP_REQUEST (source));
-       if (g_strcmp0 (content_type, "text/html") != 0) {
-               debug_printf (1, "    failed to sniff Content-Type: got %s\n",
-                             content_type ? content_type : "(NULL)");
-               errors++;
-       }
+       g_assert_cmpstr (content_type, ==, "text/html");
 
        g_input_stream_read_async (stream, buf, sizeof (buf),
                                   G_PRIORITY_DEFAULT, NULL,
@@ -213,22 +198,13 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data)
 
        stream = soup_request_send_finish (SOUP_REQUEST (source), res, &error);
        if (data->cancel) {
-               if (stream) {
-                       debug_printf (1, "    send_async succeeded??\n");
-                       errors++;
-                       g_input_stream_close (stream, NULL, NULL);
-                       g_object_unref (stream);
-               } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-                       debug_printf (1, "    send_async failed with wrong error: %s\n", error->message);
-                       errors++;
-               }
+               g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
                g_clear_error (&error);
                g_main_loop_quit (loop);
                return;
        } else {
+               g_assert_no_error (error);
                if (!stream) {
-                       debug_printf (1, "    send_async failed: %s\n", error->message);
-                       errors++;
                        g_main_loop_quit (loop);
                        g_clear_error (&error);
                        return;
@@ -236,11 +212,7 @@ test_sent (GObject *source, GAsyncResult *res, gpointer user_data)
        }
 
        content_type = soup_request_get_content_type (SOUP_REQUEST (source));
-       if (g_strcmp0 (content_type, "text/plain") != 0) {
-               debug_printf (1, "    failed to sniff Content-Type: got %s\n",
-                             content_type ? content_type : "(NULL)");
-               errors++;
-       }
+       g_assert_cmpstr (content_type, ==, "text/plain");
 
        g_input_stream_read_async (stream, buf, sizeof (buf),
                                   G_PRIORITY_DEFAULT, NULL,
@@ -307,44 +279,20 @@ do_async_test (SoupSession *session, SoupURI *uri,
 
        g_signal_handler_disconnect (session, started_id);
 
-       if (msg->status_code != expected_status) {
-               debug_printf (1, "    GET failed: %d %s (expected %d)\n",
-                             msg->status_code, msg->reason_phrase,
-                             expected_status);
-               g_object_unref (msg);
-               g_object_unref (socket);
-               errors++;
-               return;
-       }
+       soup_test_assert_message_status (msg, expected_status);
        g_object_unref (msg);
 
-       if (!expected_response) {
-               if (data.body->len) {
-                       debug_printf (1, "    body length mismatch: expected 0, got %d\n",
-                                     (int)data.body->len);
-                       errors++;
-               }
-       } else if (data.body->len != expected_response->length) {
-               debug_printf (1, "    body length mismatch: expected %d, got %d\n",
-                             (int)expected_response->length, (int)data.body->len);
-               errors++;
-       } else if (memcmp (data.body->str, expected_response->data,
-                          expected_response->length) != 0) {
-               debug_printf (1, "    body data mismatch\n");
-               errors++;
-       }
+       if (expected_response) {
+               soup_assert_cmpmem (data.body->str, data.body->len,
+                                   expected_response->data, expected_response->length);
+       } else
+               g_assert_cmpint (data.body->len, ==, 0);
+
+       if (persistent)
+               g_assert_true (soup_socket_is_connected (socket));
+       else
+               g_assert_false (soup_socket_is_connected (socket));
 
-       if (persistent) {
-               if (!soup_socket_is_connected (socket)) {
-                       debug_printf (1, "    socket not still connected!\n");
-                       errors++;
-               }
-       } else {
-               if (soup_socket_is_connected (socket)) {
-                       debug_printf (1, "    socket still connected!\n");
-                       errors++;
-               }
-       }
        g_object_unref (socket);
 
        g_string_free (data.body, TRUE);
@@ -404,18 +352,20 @@ do_test_for_thread_and_context (SoupSession *session, const char *base_uri)
 }
 
 static void
-do_simple_tests (const char *uri)
+do_simple_plain_test (gconstpointer uri)
 {
        SoupSession *session;
 
-       debug_printf (1, "Simple streaming test\n");
-
-       debug_printf (1, "  SoupSession\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
        do_test_for_thread_and_context (session, uri);
        soup_test_session_abort_unref (session);
+}
+
+static void
+do_simple_async_test (gconstpointer uri)
+{
+       SoupSession *session;
 
-       debug_printf (1, "  SoupSessionAsync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
                                         NULL);
@@ -444,45 +394,50 @@ do_test_with_context_and_type (const char *uri, gboolean plain_session)
        g_main_context_unref (async_context);
 }
 
-static gpointer
-do_test_with_context (gpointer uri)
+static void
+do_async_test_with_context (gconstpointer uri)
 {
-       debug_printf (1, "  SoupSessionAsync\n");
        do_test_with_context_and_type (uri, FALSE);
-       return NULL;
+}
+
+static void
+do_plain_test_with_context (gconstpointer uri)
+{
+       do_test_with_context_and_type (uri, TRUE);
 }
 
 static gpointer
-do_plain_test_with_context (gpointer uri)
+async_test_thread (gpointer uri)
 {
-       debug_printf (1, "  SoupSession\n");
        do_test_with_context_and_type (uri, TRUE);
        return NULL;
 }
 
-static void
-do_context_tests (const char *uri)
+static gpointer
+plain_test_thread (gpointer uri)
 {
-       debug_printf (1, "\nStreaming with a non-default-context\n");
-
-       do_plain_test_with_context ((gpointer)uri);
-       do_test_with_context ((gpointer)uri);
+       do_test_with_context_and_type (uri, FALSE);
+       return NULL;
 }
 
 static void
-do_thread_tests (const char *uri)
+do_async_test_in_thread (gconstpointer uri)
 {
        GThread *thread;
 
-       debug_printf (1, "\nStreaming in another thread\n");
-
-       thread = g_thread_new ("do_test_with_context",
-                              do_plain_test_with_context,
+       thread = g_thread_new ("do_async_test_in_thread",
+                              async_test_thread,
                               (gpointer)uri);
        g_thread_join (thread);
+}
 
-       thread = g_thread_new ("do_test_with_context",
-                              do_test_with_context,
+static void
+do_plain_test_in_thread (gconstpointer uri)
+{
+       GThread *thread;
+
+       thread = g_thread_new ("do_plain_test_in_thread",
+                              plain_test_thread,
                               (gpointer)uri);
        g_thread_join (thread);
 }
@@ -514,88 +469,49 @@ do_sync_request (SoupSession *session, SoupRequest *request,
        in = soup_request_send (request, NULL, &error);
        g_signal_handler_disconnect (session, started_id);
        if (cancel) {
-               if (in) {
-                       debug_printf (1, "    send succeeded??\n");
-                       errors++;
-                       g_input_stream_close (in, NULL, NULL);
-                       g_object_unref (in);
-               } else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-                       debug_printf (1, "    send failed with wrong error: %s\n", error->message);
-                       errors++;
-               }
+               g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
                g_clear_error (&error);
                g_object_unref (msg);
                g_object_unref (socket);
                return;
        } else if (!in) {
-               debug_printf (1, "    soup_request_send failed: %s\n",
-                             error->message);
-               g_object_unref (msg);
+               g_assert_no_error (error);
                g_clear_error (&error);
-               g_object_unref (socket);
-               errors++;
-               return;
-       }
-
-       if (msg->status_code != expected_status) {
-               debug_printf (1, "    GET failed: %d %s\n", msg->status_code,
-                             msg->reason_phrase);
                g_object_unref (msg);
-               g_object_unref (in);
                g_object_unref (socket);
-               errors++;
                return;
        }
+
+       soup_test_assert_message_status (msg, expected_status);
        g_object_unref (msg);
 
        body = g_string_new (NULL);
        do {
                nread = g_input_stream_read (in, buf, sizeof (buf),
                                             NULL, &error);
+               g_assert_no_error (error);
                if (nread == -1) {
-                       debug_printf (1, "    g_input_stream_read failed: %s\n",
-                                     error->message);
                        g_clear_error (&error);
-                       errors++;
                        break;
                }
                g_string_append_len (body, buf, nread);
        } while (nread > 0);
 
-       if (!g_input_stream_close (in, NULL, &error)) {
-               debug_printf (1, "    g_input_stream_close failed: %s\n",
-                             error->message);
-               g_clear_error (&error);
-               errors++;
-       }
+       g_input_stream_close (in, NULL, &error);
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (in);
 
-       if (!expected_response) {
-               if (body->len) {
-                       debug_printf (1, "    body length mismatch: expected 0, got %d\n",
-                                     (int)body->len);
-                       errors++;
-               }
-       } else if (body->len != expected_response->length) {
-               debug_printf (1, "    body length mismatch: expected %d, got %d\n",
-                             (int)expected_response->length, (int)body->len);
-               errors++;
-       } else if (memcmp (body->str, expected_response->data, body->len) != 0) {
-               debug_printf (1, "    body data mismatch\n");
-               errors++;
-       }
+       if (expected_response) {
+               soup_assert_cmpmem (body->str, body->len,
+                                   expected_response->data, expected_response->length);
+       } else
+               g_assert_cmpint (body->len, ==, 0);
 
-       if (persistent) {
-               if (!soup_socket_is_connected (socket)) {
-                       debug_printf (1, "    socket not still connected!\n");
-                       errors++;
-               }
-       } else {
-               if (soup_socket_is_connected (socket)) {
-                       debug_printf (1, "    socket still connected!\n");
-                       errors++;
-               }
-       }
+       if (persistent)
+               g_assert_true (soup_socket_is_connected (socket));
+       else
+               g_assert_false (soup_socket_is_connected (socket));
        g_object_unref (socket);
 
        g_string_free (body, TRUE);
@@ -670,24 +586,26 @@ do_sync_tests_for_session (SoupSession *session, const char *uri_string)
 }
 
 static void
-do_sync_tests (const char *uri_string)
+do_plain_sync_test (gconstpointer uri)
 {
        SoupSession *session;
-       SoupRequester *requester;
 
-       debug_printf (1, "\nSync streaming\n");
-
-       debug_printf (1, "  SoupSession\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
-       do_sync_tests_for_session (session, uri_string);
+       do_sync_tests_for_session (session, uri);
        soup_test_session_abort_unref (session);
+}
+
+static void
+do_sync_sync_test (gconstpointer uri)
+{
+       SoupSession *session;
+       SoupRequester *requester;
 
-       debug_printf (1, "  SoupSessionSync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
        requester = soup_requester_new ();
        soup_session_add_feature (session, SOUP_SESSION_FEATURE (requester));
        g_object_unref (requester);
-       do_sync_tests_for_session (session, uri_string);
+       do_sync_tests_for_session (session, uri);
        soup_test_session_abort_unref (session);
 }
 
@@ -708,10 +626,8 @@ do_null_char_request (SoupSession *session, const char *encoded_data,
 
        request = soup_session_request_uri (session, uri, NULL);
        stream = soup_test_request_send (request, NULL, 0, &error);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "    could not send request: %s\n", error->message);
-               errors++;
                g_error_free (error);
                g_object_unref (request);
                soup_uri_free (uri);
@@ -719,27 +635,14 @@ do_null_char_request (SoupSession *session, const char *encoded_data,
        }
 
        g_input_stream_read_all (stream, buf, sizeof (buf), &nread, NULL, &error);
-       if (error) {
-               debug_printf (1, "    could not read response: %s\n", error->message);
-               errors++;
-               g_clear_error (&error);
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
        soup_test_request_close_stream (request, stream, NULL, &error);
-       if (error) {
-               debug_printf (1, "    could not close stream: %s\n", error->message);
-               errors++;
-               g_clear_error (&error);
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
-       if (nread != expected_len) {
-               debug_printf (1, "    response length mismatch: expected %d, got %lu\n",
-                             expected_len, (gulong)nread);
-               errors++;
-       } else if (memcmp (buf, expected_data, nread) != 0) {
-               debug_printf (1, "    response data mismatch\n");
-               errors++;
-       }
+       soup_assert_cmpmem (buf, nread, expected_data, expected_len);
 
        g_object_unref (stream);
        g_object_unref (request);
@@ -768,18 +671,20 @@ do_null_char_test_for_session (SoupSession *session)
 }
 
 static void
-do_null_char_tests (void)
+do_plain_null_char_test (void)
 {
        SoupSession *session;
 
-       debug_printf (1, "\nStreaming data URLs containing null chars\n");
-
-       debug_printf (1, "  SoupSession\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
        do_null_char_test_for_session (session);
        soup_test_session_abort_unref (session);
+}
+
+static void
+do_async_null_char_test (void)
+{
+       SoupSession *session;
 
-       debug_printf (1, "  SoupSessionAsync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
                                         NULL);
@@ -812,10 +717,8 @@ do_close_test_for_session (SoupSession *session,
 
        request = soup_session_request_uri (session, uri, NULL);
        stream = soup_test_request_send (request, NULL, 0, &error);
-
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "      could not send request: %s\n", error->message);
-               errors++;
                g_error_free (error);
                g_object_unref (request);
                return;
@@ -823,17 +726,11 @@ do_close_test_for_session (SoupSession *session,
 
        start = g_get_monotonic_time ();
        soup_test_request_close_stream (request, stream, NULL, &error);
-       if (error) {
-               debug_printf (1, "      could not close stream: %s\n", error->message);
-               errors++;
-               g_clear_error (&error);
-       }
+       g_assert_no_error (error);
+       g_clear_error (&error);
        end = g_get_monotonic_time ();
 
-       if (end - start > 500000) {
-               debug_printf (1, "      close() waited for response to complete!\n");
-               errors++;
-       }
+       g_assert_cmpint (end - start, <=, 500000);
 
        g_object_unref (stream);
        g_object_unref (request);
@@ -847,9 +744,8 @@ do_close_test_for_session (SoupSession *session,
        g_object_unref (msg);
 
        stream = soup_test_request_send (request, NULL, 0, &error);
+       g_assert_no_error (error);
        if (error) {
-               debug_printf (1, "      could not send request: %s\n", error->message);
-               errors++;
                g_error_free (error);
                g_object_unref (request);
                return;
@@ -858,39 +754,43 @@ do_close_test_for_session (SoupSession *session,
        cancellable = g_cancellable_new ();
        g_cancellable_cancel (cancellable);
        soup_test_request_close_stream (request, stream, cancellable, &error);
-       if (error && !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
-               debug_printf (1, "      did not get expected error: %s\n", error->message);
-               errors++;
-               g_clear_error (&error);
-       }
+       if (error)
+               g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
+       g_clear_error (&error);
 
-       if (!finished) {
-               debug_printf (1, "      message did not finish!\n");
-               errors++;
-       }
+       g_assert_true (finished);
 
        g_object_unref (stream);
        g_object_unref (request);
 }
 
 static void
-do_close_tests (const char *uri)
+do_async_close_test (gconstpointer uri)
 {
        SoupSession *session;
        SoupURI *slow_uri;
 
-       debug_printf (1, "\nClosing stream before end should cancel\n");
-
        slow_uri = soup_uri_new (uri);
        soup_uri_set_path (slow_uri, "/slow");
 
-       debug_printf (1, "  SoupSessionAsync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
                                         NULL);
        do_close_test_for_session (session, slow_uri);
        soup_test_session_abort_unref (session);
 
+       soup_uri_free (slow_uri);
+}
+
+static void
+do_sync_close_test (gconstpointer uri)
+{
+       SoupSession *session;
+       SoupURI *slow_uri;
+
+       slow_uri = soup_uri_new (uri);
+       soup_uri_set_path (slow_uri, "/slow");
+
        debug_printf (1, "  SoupSessionSync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
@@ -905,6 +805,7 @@ int
 main (int argc, char **argv)
 {
        char *uri;
+       int ret;
 
        test_init (argc, argv, NULL);
        get_index ();
@@ -914,12 +815,20 @@ main (int argc, char **argv)
 
        uri = g_strdup_printf ("http://127.0.0.1:%u/foo";, soup_server_get_port (server));
 
-       do_simple_tests (uri);
-       do_thread_tests (uri);
-       do_context_tests (uri);
-       do_sync_tests (uri);
-       do_null_char_tests ();
-       do_close_tests (uri);
+       g_test_add_data_func ("/requester/simple/SoupSession", uri, do_simple_plain_test);
+       g_test_add_data_func ("/requester/simple/SoupSessionAsync", uri, do_simple_async_test);
+       g_test_add_data_func ("/requester/threaded/SoupSession", uri, do_plain_test_in_thread);
+       g_test_add_data_func ("/requester/threaded/SoupSessionAsync", uri, do_async_test_in_thread);
+       g_test_add_data_func ("/requester/context/SoupSession", uri, do_plain_test_with_context);
+       g_test_add_data_func ("/requester/context/SoupSessionAsync", uri, do_async_test_with_context);
+       g_test_add_data_func ("/requester/sync/SoupSession", uri, do_plain_sync_test);
+       g_test_add_data_func ("/requester/sync/SoupSessionSync", uri, do_sync_sync_test);
+       g_test_add_func ("/requester/null-char/SoupSession", do_plain_null_char_test);
+       g_test_add_func ("/requester/null-char/SoupSessionAsync", do_async_null_char_test);
+       g_test_add_data_func ("/requester/close/SoupSessionAsync", uri, do_async_close_test);
+       g_test_add_data_func ("/requester/close/SoupSessionSync", uri, do_sync_close_test);
+
+       ret = g_test_run ();
 
        g_free (uri);
        soup_buffer_free (response);
@@ -927,5 +836,5 @@ main (int argc, char **argv)
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/resource-test.c b/tests/resource-test.c
index 21e2f98..e41c603 100644
--- a/tests/resource-test.c
+++ b/tests/resource-test.c
@@ -39,19 +39,6 @@ register_gresource (void)
        g_resource_unref (resource);
 }
 
-static void
-check_results (GString *body)
-{
-       if (body->len != index_buffer->length) {
-               debug_printf (1, "    body length mismatch: expected %d, got %d\n",
-                             (int)index_buffer->length, (int)body->len);
-               errors++;
-       } else if (memcmp (body->str, index_buffer->data, body->len) != 0) {
-               debug_printf (1, "    body data mismatch\n");
-               errors++;
-       }
-}
-
 typedef struct {
        GString *body;
        char buffer[1024];
@@ -65,11 +52,8 @@ stream_closed (GObject *source, GAsyncResult *result, gpointer user_data)
        AsyncRequestData *data = user_data;
        GError *error = NULL;
 
-       if (!g_input_stream_close_finish (in, result, &error)) {
-               debug_printf (1, "    close failed: %s\n", error->message);
-               g_error_free (error);
-               errors++;
-       }
+       g_input_stream_close_finish (in, result, &error);
+       g_assert_no_error (error);
        g_main_loop_quit (data->loop);
        g_object_unref (in);
 }
@@ -84,12 +68,10 @@ test_read_ready (GObject *source, GAsyncResult *result, gpointer user_data)
 
        nread = g_input_stream_read_finish (in, result, &error);
        if (nread == -1) {
-               debug_printf (1, "    g_input_stream_read failed: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_clear_error (&error);
                g_input_stream_close (in, NULL, NULL);
                g_object_unref (in);
-               errors++;
                return;
        } else if (nread == 0) {
                g_input_stream_close_async (in, G_PRIORITY_DEFAULT, NULL,
@@ -112,10 +94,8 @@ async_request_sent (GObject *source, GAsyncResult *result, gpointer user_data)
 
        in = soup_request_send_finish (SOUP_REQUEST (source), result, &error);
        if (!in) {
-               debug_printf (1, "    soup_request_send_async failed: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_clear_error (&error);
-               errors++;
                return;
        }
 
@@ -136,7 +116,8 @@ do_async_request (SoupRequest *request)
        g_main_loop_run (data.loop);
        g_main_loop_unref (data.loop);
 
-       check_results (data.body);
+       soup_assert_cmpmem (data.body->str, data.body->len,
+                           index_buffer->data, index_buffer->length);
        g_string_free (data.body, TRUE);
 }
 
@@ -151,10 +132,8 @@ do_sync_request (SoupRequest *request)
 
        in = soup_request_send (request, NULL, &error);
        if (!in) {
-               debug_printf (1, "    soup_request_send failed: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_clear_error (&error);
-               errors++;
                return;
        }
 
@@ -163,127 +142,111 @@ do_sync_request (SoupRequest *request)
                nread = g_input_stream_read (in, buffer, sizeof (buffer),
                                             NULL, &error);
                if (nread == -1) {
-                       debug_printf (1, "    g_input_stream_read failed: %s\n",
-                                     error->message);
+                       g_assert_no_error (error);
                        g_clear_error (&error);
-                       errors++;
                        break;
                }
                g_string_append_len (body, buffer, nread);
        } while (nread > 0);
 
-       if (!g_input_stream_close (in, NULL, &error)) {
-               debug_printf (1, "    g_input_stream_close failed: %s\n",
-                             error->message);
-               g_clear_error (&error);
-               errors++;
-       }
+       g_input_stream_close (in, NULL, &error);
+       g_assert_no_error (error);
+       g_clear_error (&error);
        g_object_unref (in);
 
-       check_results (body);
+       soup_assert_cmpmem (body->str, body->len, index_buffer->data, index_buffer->length);
        g_string_free (body, TRUE);
 }
 
 static void
-do_request_file_test (SoupSession *session,
-                     gboolean     async)
+do_request (const char *uri_string, gconstpointer type)
 {
+       SoupSession *session;
        SoupRequest *request;
-       GFile *index;
-       char *uri_string;
-       SoupURI *uri;
+       GError *error = NULL;
 
-       index = g_file_new_for_path (SRCDIR "/index.txt");
-       uri_string = g_file_get_uri (index);
-       g_object_unref (index);
+       session = soup_test_session_new (GPOINTER_TO_SIZE (type),
+                                        SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
+                                        NULL);
 
-       uri = soup_uri_new (uri_string);
-       g_free (uri_string);
+       request = soup_session_request (session, uri_string, &error);
+       g_assert_no_error (error);
 
-       request = soup_session_request_uri (session, uri, NULL);
-       if (async)
+       if (SOUP_IS_SESSION_ASYNC (session))
                do_async_request (request);
        else
                do_sync_request (request);
+
        g_object_unref (request);
+       soup_test_session_abort_unref (session);
+}
 
-       soup_uri_free (uri);
+static void
+do_request_file_test (gconstpointer type)
+{
+       GFile *index;
+       char *uri_string;
+
+       index = g_file_new_for_path (SRCDIR "/index.txt");
+       uri_string = g_file_get_uri (index);
+       g_object_unref (index);
+
+       do_request (uri_string, type);
+       g_free (uri_string);
 }
 
 static void
-do_request_data_test (SoupSession *session,
-                     gboolean     async)
+do_request_data_test (gconstpointer type)
 {
-       SoupRequest *request;
        gchar *base64;
        char *uri_string;
-       SoupURI *uri;
 
        base64 = g_base64_encode ((const guchar *)index_buffer->data, index_buffer->length);
        uri_string = g_strdup_printf ("data:text/plain;charset=utf8;base64,%s", base64);
        g_free (base64);
 
-       uri = soup_uri_new (uri_string);
+       do_request (uri_string, type);
        g_free (uri_string);
-
-       request = soup_session_request_uri (session, uri, NULL);
-       if (async)
-               do_async_request (request);
-       else
-               do_sync_request (request);
-       g_object_unref (request);
-
-       soup_uri_free (uri);
 }
 
 static void
-do_request_gresource_test (SoupSession *session,
-                          gboolean     async)
+do_request_gresource_test (gconstpointer type)
 {
-       SoupRequest *request;
-       SoupURI *uri;
-
-       uri = soup_uri_new ("resource:///org/gnome/libsoup/tests/index.txt");
-       request = soup_session_request_uri (session, uri, NULL);
-       if (async)
-               do_async_request (request);
-       else
-               do_sync_request (request);
-       g_object_unref (request);
-
-       soup_uri_free (uri);
+       do_request ("resource:///org/gnome/libsoup/tests/index.txt", type);
 }
 
 int
 main (int argc, char **argv)
 {
-       SoupSession *session;
+       int ret;
 
        test_init (argc, argv, NULL);
 
        get_index ();
        register_gresource ();
 
-       /* Sync tests */
-       session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
-
-       do_request_file_test (session, FALSE);
-       do_request_data_test (session, FALSE);
-       do_request_gresource_test (session, FALSE);
-
-       soup_test_session_abort_unref (session);
-
-       /* Async tests */
-       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
-                                        SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
-                                        NULL);
-
-       do_request_file_test (session, TRUE);
-       do_request_data_test (session, TRUE);
-       do_request_gresource_test (session, TRUE);
-
-       soup_test_session_abort_unref (session);
+       g_test_add_data_func ("/resource/sync/file",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_SYNC),
+                             do_request_file_test);
+       g_test_add_data_func ("/resource/sync/data",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_SYNC),
+                             do_request_data_test);
+       g_test_add_data_func ("/resource/sync/gresource",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_SYNC),
+                             do_request_gresource_test);
+
+       g_test_add_data_func ("/resource/async/file",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_ASYNC),
+                             do_request_file_test);
+       g_test_add_data_func ("/resource/async/data",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_ASYNC),
+                             do_request_data_test);
+       g_test_add_data_func ("/resource/async/gresource",
+                             GSIZE_TO_POINTER (SOUP_TYPE_SESSION_ASYNC),
+                             do_request_gresource_test);
+
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/server-auth-test.c b/tests/server-auth-test.c
index 78cd068..77a5dba 100644
--- a/tests/server-auth-test.c
+++ b/tests/server-auth-test.c
@@ -90,46 +90,18 @@ do_test (int n, SoupURI *base_uri, const char *path,
        g_ptr_array_free (args, TRUE);
        g_free (uri_str);
 
-       if (server_requests_basic != test_data.server_requested_basic) {
-               errors++;
-               if (test_data.server_requested_basic)
-                       debug_printf (1, "  Server sent WWW-Authenticate: Basic, but shouldn't have!\n");
-               else
-                       debug_printf (1, "  Server didn't send WWW-Authenticate: Basic, but should have!\n");
-       }
-       if (server_requests_digest != test_data.server_requested_digest) {
-               errors++;
-               if (test_data.server_requested_digest)
-                       debug_printf (1, "  Server sent WWW-Authenticate: Digest, but shouldn't have!\n");
-               else
-                       debug_printf (1, "  Server didn't send WWW-Authenticate: Digest, but should have!\n");
-       }
-       if (client_sends_basic != test_data.client_sent_basic) {
-               errors++;
-               if (test_data.client_sent_basic)
-                       debug_printf (1, "  Client sent Authorization: Basic, but shouldn't have!\n");
-               else
-                       debug_printf (1, "  Client didn't send Authorization: Basic, but should have!\n");
-       }
-       if (client_sends_digest != test_data.client_sent_digest) {
-               errors++;
-               if (test_data.client_sent_digest)
-                       debug_printf (1, "  Client sent Authorization: Digest, but shouldn't have!\n");
-               else
-                       debug_printf (1, "  Client didn't send Authorization: Digest, but should have!\n");
-       }
-       if (success && !test_data.succeeded) {
-               errors++;
-               debug_printf (1, "  Should have succeeded, but didn't!\n");
-       } else if (!success && test_data.succeeded) {
-               errors++;
-               debug_printf (1, "  Should not have succeeded, but did!\n");
-       }
+       g_assert_cmpint (server_requests_basic, ==, test_data.server_requested_basic);
+       g_assert_cmpint (server_requests_digest, ==, test_data.server_requested_digest);
+       g_assert_cmpint (client_sends_basic, ==, test_data.client_sent_basic);
+       g_assert_cmpint (client_sends_digest, ==, test_data.client_sent_digest);
+
+       g_assert_cmpint (success, ==, test_data.succeeded);
 }
 
 static void
-do_auth_tests (SoupURI *base_uri)
+do_auth_tests (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        int i, n = 1;
        gboolean use_basic, use_digest, good_user, good_password;
        gboolean preemptive_basic, good_auth;
@@ -317,6 +289,7 @@ main (int argc, char **argv)
        SoupServer *server;
        SoupURI *uri;
        SoupAuthDomain *auth_domain;
+       int ret;
 
        test_init (argc, argv, no_test_entry);
 
@@ -351,11 +324,17 @@ main (int argc, char **argv)
        if (run_tests) {
                uri = soup_uri_new ("http://127.0.0.1";);
                soup_uri_set_port (uri, soup_server_get_port (server));
-               do_auth_tests (uri);
+
+               /* FIXME: split this up! */
+               g_test_add_data_func ("/server-auth", uri, do_auth_tests);
+
+               ret = g_test_run ();
+
                soup_uri_free (uri);
        } else {
                g_print ("Listening on port %d\n", soup_server_get_port (server));
                g_main_loop_run (loop);
+               ret = 0;
        }
 
        g_main_loop_unref (loop);
@@ -363,7 +342,7 @@ main (int argc, char **argv)
 
        if (run_tests)
                test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_CURL */
diff --git a/tests/server-test.c b/tests/server-test.c
index 3ff7cad..ec5b690 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -17,8 +17,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
                                     "X-Handled-By", "server_callback");
 
        if (!strcmp (path, "*")) {
-               debug_printf (1, "    default server_callback got request for '*'!\n");
-               errors++;
+               soup_test_assert (FALSE, "default server_callback got request for '*'");
                soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
                return;
        }
@@ -42,8 +41,7 @@ server_star_callback (SoupServer *server, SoupMessage *msg,
                                     "X-Handled-By", "star_callback");
 
        if (strcmp (path, "*") != 0) {
-               debug_printf (1, "    server_star_callback got request for '%s'!\n", path);
-               errors++;
+               soup_test_assert (FALSE, "server_star_callback got request for '%s'", path);
                soup_message_set_status (msg, SOUP_STATUS_INTERNAL_SERVER_ERROR);
                return;
        }
@@ -77,19 +75,10 @@ do_star_test (void)
        msg = soup_message_new_from_uri ("OPTIONS", star_uri);
        soup_session_send_message (session, msg);
 
-       if (msg->status_code != SOUP_STATUS_NOT_FOUND) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_NOT_FOUND);
        handled_by = soup_message_headers_get_one (msg->response_headers,
                                                   "X-Handled-By");
-       if (handled_by) {
-               /* Should have been rejected by SoupServer directly */
-               debug_printf (1, "    Message reached handler '%s'\n",
-                             handled_by);
-               errors++;
-       }
+       g_assert_cmpstr (handled_by, ==, NULL);
        g_object_unref (msg);
 
        soup_server_add_handler (server, "*", server_star_callback, NULL, NULL);
@@ -98,21 +87,10 @@ do_star_test (void)
        msg = soup_message_new_from_uri ("OPTIONS", star_uri);
        soup_session_send_message (session, msg);
 
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    Unexpected response: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        handled_by = soup_message_headers_get_one (msg->response_headers,
                                                   "X-Handled-By");
-       if (!handled_by) {
-               debug_printf (1, "    Message did not reach handler!\n");
-               errors++;
-       } else if (strcmp (handled_by, "star_callback") != 0) {
-               debug_printf (1, "    Message reached incorrect handler '%s'\n",
-                             handled_by);
-               errors++;
-       }
+       g_assert_cmpstr (handled_by, ==, "star_callback");
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -150,10 +128,8 @@ do_one_server_aliases_test (SoupURI    *uri,
        g_object_unref (addr);
        g_object_unref (client);
        if (!conn) {
-               debug_printf (1, "    error connecting to server: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                return;
        }
 
@@ -168,10 +144,8 @@ do_one_server_aliases_test (SoupURI    *uri,
        g_string_append (req, "Connection: close\r\n\r\n");
 
        if (!g_output_stream_write_all (out, req->str, req->len, NULL, NULL, &error)) {
-               debug_printf (1, "    error sending request: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                g_object_unref (conn);
                g_string_free (req, TRUE);
                return;
@@ -179,20 +153,16 @@ do_one_server_aliases_test (SoupURI    *uri,
        g_string_free (req, TRUE);
 
        if (!g_input_stream_read_all (in, buf, sizeof (buf), NULL, NULL, &error)) {
-               debug_printf (1, "    error reading response: %s\n",
-                             error->message);
+               g_assert_no_error (error);
                g_error_free (error);
-               errors++;
                g_object_unref (conn);
                return;
        }
 
-       if ((succeed && !g_str_has_prefix (buf, "HTTP/1.1 200 ")) ||
-           (!succeed && !g_str_has_prefix (buf, "HTTP/1.1 400 "))) {
-               debug_printf (1, "    unexpected response: %.*s\n",
-                             (int) strcspn (buf, "\r\n"), buf);
-               errors++;
-       }
+       if (succeed)
+               g_assert_true (g_str_has_prefix (buf, "HTTP/1.1 200 "));
+       else
+               g_assert_true (g_str_has_prefix (buf, "HTTP/1.1 400 "));
 
        g_io_stream_close (G_IO_STREAM (conn), NULL, NULL);
        g_object_unref (conn);
@@ -238,12 +208,7 @@ do_dot_dot_test (void)
        soup_uri_free (uri);
 
        soup_session_send_message (session, msg);
-
-       if (msg->status_code != SOUP_STATUS_BAD_REQUEST) {
-               debug_printf (1, "      FAILED: %d %s (expected Bad Request)\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_BAD_REQUEST);
        g_object_unref (msg);
 
        soup_test_session_abort_unref (session);
@@ -257,24 +222,16 @@ ipv6_server_callback (SoupServer *server, SoupMessage *msg,
        const char *host;
        char expected_host[128];
 
-       host = soup_message_headers_get_one (msg->request_headers, "Host");
-       if (!host) {
-               debug_printf (1, "    request has no Host header!\n");
-               errors++;
-               soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
-               return;
-       }
-
        g_snprintf (expected_host, sizeof (expected_host),
                    "[::1]:%d", soup_server_get_port (server));
 
-       if (strcmp (host, expected_host) == 0)
-               soup_message_set_status (msg, SOUP_STATUS_OK);
-       else {
-               debug_printf (1, "    request has incorrect Host header '%s'\n", host);
-               errors++;
+       host = soup_message_headers_get_one (msg->request_headers, "Host");
+       g_assert_cmpstr (host, ==, expected_host);
+
+       if (g_test_failed ())
                soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST);
-       }
+       else
+               soup_message_set_status (msg, SOUP_STATUS_OK);
 }
 
 static void
@@ -309,22 +266,14 @@ do_ipv6_test (void)
        debug_printf (1, "  HTTP/1.1\n");
        msg = soup_message_new_from_uri ("GET", ipv6_uri);
        soup_session_send_message (session, msg);
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    request failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
 
        debug_printf (1, "  HTTP/1.0\n");
        msg = soup_message_new_from_uri ("GET", ipv6_uri);
        soup_message_set_http_version (msg, SOUP_HTTP_1_0);
        soup_session_send_message (session, msg);
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "    request failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
        g_object_unref (msg);
 
        soup_uri_free (ipv6_uri);
@@ -337,6 +286,7 @@ main (int argc, char **argv)
 {
        char *http_aliases[] = { "dav", NULL };
        char *https_aliases[] = { "davs", NULL };
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -359,10 +309,12 @@ main (int argc, char **argv)
                              NULL);
        }
 
-       do_star_test ();
-       do_server_aliases_test ();
-       do_dot_dot_test ();
-       do_ipv6_test ();
+       g_test_add_func ("/server/OPTIONS *", do_star_test);
+       g_test_add_func ("/server/aliases", do_server_aliases_test);
+       g_test_add_func ("/server/..-in-path", do_dot_dot_test);
+       g_test_add_func ("/server/ipv6", do_ipv6_test);
+
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
        soup_test_server_quit_unref (server);
@@ -373,5 +325,5 @@ main (int argc, char **argv)
        }
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/session-test.c b/tests/session-test.c
index 205885d..a6ce2c4 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -58,7 +58,7 @@ cancel_message_cb (SoupMessage *msg, gpointer session)
 
 static void
 do_test_for_session (SoupSession *session,
-                    const char *uri, const char *timeout_uri,
+                    const char *uri,
                     gboolean queue_is_async,
                     gboolean send_is_blocking,
                     gboolean cancel_is_immediate)
@@ -66,10 +66,13 @@ do_test_for_session (SoupSession *session,
        SoupMessage *msg;
        gboolean finished, local_timeout;
        guint timeout_id;
+       char *timeout_uri;
 
        debug_printf (1, "  queue_message\n");
        debug_printf (2, "    requesting timeout\n");
+       timeout_uri = g_strdup_printf ("%s/request-timeout", uri);
        msg = soup_message_new ("GET", timeout_uri);
+       g_free (timeout_uri);
        soup_session_send_message (session, msg);
        g_object_unref (msg);
 
@@ -81,27 +84,15 @@ do_test_for_session (SoupSession *session,
        debug_printf (2, "    got timeout\n");
 
        if (queue_is_async) {
-               if (server_processed_message) {
-                       debug_printf (1, "    message processed without running main loop!\n");
-                       errors++;
-               }
+               g_assert_false (server_processed_message);
                debug_printf (2, "    waiting for finished\n");
                while (!finished)
                        g_main_context_iteration (NULL, TRUE);
-               if (!server_processed_message) {
-                       debug_printf (1, "    message finished without server seeing it???\n");
-                       errors++;
-               }
+               g_assert_true (server_processed_message);
        } else {
-               if (!server_processed_message) {
-                       debug_printf (1, "    server failed to immediately receive message!\n");
-                       errors++;
-               }
+               g_assert_true (server_processed_message);
+               g_assert_false (finished);
                debug_printf (2, "    waiting for finished\n");
-               if (finished) {
-                       debug_printf (1, "    message finished without main loop running???\n");
-                       errors++;
-               }
                while (!finished)
                        g_main_context_iteration (NULL, TRUE);
        }
@@ -112,21 +103,14 @@ do_test_for_session (SoupSession *session,
        timeout_id = g_idle_add_full (G_PRIORITY_HIGH, timeout_cb, &local_timeout, NULL);
        soup_session_send_message (session, msg);
 
-       if (!server_processed_message) {
-               debug_printf (1, "    message finished without server seeing it???\n");
-               errors++;
-       }
+       g_assert_true (server_processed_message);
 
        if (send_is_blocking) {
-               if (local_timeout) {
-                       debug_printf (1, "    send_message ran main loop!\n");
-                       errors++;
-               }
+               soup_test_assert (!local_timeout,
+                                 "send_message ran main loop");
        } else {
-               if (!local_timeout) {
-                       debug_printf (1, "    send_message didn't run main loop!\n");
-                       errors++;
-               }
+               soup_test_assert (local_timeout,
+                                 "send_message didn't run main loop");
        }
 
        if (!local_timeout)
@@ -146,65 +130,48 @@ do_test_for_session (SoupSession *session,
        loop = g_main_loop_new (NULL, FALSE);
        g_main_loop_run (loop);
 
-       if (cancel_is_immediate) {
-               if (!finished) {
-                       debug_printf (1, "    cancel did not finish message!\n");
-                       errors++;
-                       debug_printf (2, "    waiting for finished\n");
-                       while (!finished)
-                               g_main_context_iteration (NULL, TRUE);
-               }
-       } else {
-               if (finished) {
-                       debug_printf (1, "    cancel finished message!\n");
-                       errors++;
-               } else {
-                       while (!finished)
-                               g_main_context_iteration (NULL, TRUE);
-               }
-       }
+       if (cancel_is_immediate)
+               g_assert_true (finished);
+       else
+               g_assert_false (finished);
 
-       if (msg->status_code != SOUP_STATUS_CANCELLED) {
-               debug_printf (1, "    message finished with status %d %s!\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
+       if (!finished) {
+               debug_printf (2, "    waiting for finished\n");
+               while (!finished)
+                       g_main_context_iteration (NULL, TRUE);
        }
+
+       soup_test_assert_message_status (msg, SOUP_STATUS_CANCELLED);
        g_object_unref (msg);
 }
 
 static void
-do_plain_tests (char *uri, char *timeout_uri)
+do_plain_tests (gconstpointer uri)
 {
        SoupSession *session;
 
-       debug_printf (1, "SoupSession\n");
-
        session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
-       do_test_for_session (session, uri, timeout_uri, TRUE, TRUE, FALSE);
+       do_test_for_session (session, uri, TRUE, TRUE, FALSE);
        soup_test_session_abort_unref (session);
 }
 
 static void
-do_async_tests (char *uri, char *timeout_uri)
+do_async_tests (gconstpointer uri)
 {
        SoupSession *session;
 
-       debug_printf (1, "\nSoupSessionAsync\n");
-
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       do_test_for_session (session, uri, timeout_uri, TRUE, FALSE, TRUE);
+       do_test_for_session (session, uri, TRUE, FALSE, TRUE);
        soup_test_session_abort_unref (session);
 }
 
 static void
-do_sync_tests (char *uri, char *timeout_uri)
+do_sync_tests (gconstpointer uri)
 {
        SoupSession *session;
 
-       debug_printf (1, "\nSoupSessionSync\n");
-
        session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
-       do_test_for_session (session, uri, timeout_uri, FALSE, TRUE, FALSE);
+       do_test_for_session (session, uri, FALSE, TRUE, FALSE);
        soup_test_session_abort_unref (session);
 }
 
@@ -214,20 +181,20 @@ priority_test_finished_cb (SoupSession *session, SoupMessage *msg, gpointer user
        guint *finished_count = user_data;
        SoupMessagePriority priority = soup_message_get_priority (msg);
 
-       if (priority != expected_priorities[*finished_count]) {
-               debug_printf (1, "    message %d should have priority %d (%d found)\n",
-                             *finished_count, expected_priorities[*finished_count], priority);
-               errors++;
-       } else
-               debug_printf (1, "  received message %d with priority %d\n",
-                             *finished_count, priority);
+       debug_printf (1, "  received message %d with priority %d\n",
+                     *finished_count, priority);
+
+       soup_test_assert (priority == expected_priorities[*finished_count],
+                         "message %d should have priority %d (%d found)",
+                         *finished_count, expected_priorities[*finished_count], priority);
 
        (*finished_count)++;
 }
 
 static void
-do_priority_tests (char *uri)
+do_priority_tests (gconstpointer data)
 {
+       const char *uri = data;
        SoupSession *session;
        int i, finished_count = 0;
        SoupMessagePriority priorities[] =
@@ -276,16 +243,14 @@ test_session_properties (const char *name,
                      SOUP_SESSION_PROXY_RESOLVER, &proxy_resolver,
                      SOUP_SESSION_TLS_DATABASE, &tlsdb,
                      NULL);
-       if (proxy_resolver != expected_proxy_resolver) {
-               debug_printf (1, "  %s has %s proxy resolver!\n",
-                             name, proxy_resolver ? (expected_proxy_resolver ? "wrong" : "a") : "no");
-               errors++;
-       }
-       if (tlsdb != expected_tls_database) {
-               debug_printf (1, "  %s has %s TLS database!\n",
-                             name, tlsdb ? (expected_tls_database ? "wrong" : "a") : "no");
-               errors++;
-       }
+
+       soup_test_assert (proxy_resolver == expected_proxy_resolver,
+                         "%s has %s proxy resolver",
+                         name, proxy_resolver ? (expected_proxy_resolver ? "wrong" : "a") : "no");
+       soup_test_assert (tlsdb == expected_tls_database,
+                         "%s has %s TLS database",
+                         name, tlsdb ? (expected_tls_database ? "wrong" : "a") : "no");
+
        g_clear_object (&proxy_resolver);
        g_clear_object (&tlsdb);
 }
@@ -343,11 +308,7 @@ do_property_tests (void)
                      NULL);
        test_session_properties ("Session with non-NULL :proxy-uri", session,
                                 proxy_resolver, default_tlsdb);
-       if (!G_IS_SIMPLE_PROXY_RESOLVER (proxy_resolver)) {
-               debug_printf (1, "  proxy resolver had wrong type (%s)\n",
-                             G_OBJECT_TYPE_NAME (proxy_resolver));
-               errors++;
-       }
+       g_assert_cmpstr (G_OBJECT_TYPE_NAME (proxy_resolver), ==, "GSimpleProxyResolver");
        g_object_unref (proxy_resolver);
        g_object_unref (session);
        soup_uri_free (uri);
@@ -402,6 +363,7 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        char *uri, *timeout_uri;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -411,16 +373,18 @@ main (int argc, char **argv)
                               soup_server_get_port (server));
        timeout_uri = g_strdup_printf ("%s/request-timeout", uri);
 
-       do_plain_tests (uri, timeout_uri);
-       do_async_tests (uri, timeout_uri);
-       do_sync_tests (uri, timeout_uri);
-       do_priority_tests (uri);
-       do_property_tests ();
+       g_test_add_data_func ("/session/SoupSession", uri, do_plain_tests);
+       g_test_add_data_func ("/session/SoupSessionAsync", uri, do_async_tests);
+       g_test_add_data_func ("/session/SoupSessionSync", uri, do_sync_tests);
+       g_test_add_data_func ("/session/priority", uri, do_priority_tests);
+       g_test_add_func ("/session/property", do_property_tests);
+
+       ret = g_test_run ();
 
        g_free (uri);
        g_free (timeout_uri);
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/sniffing-test.c b/tests/sniffing-test.c
index cbebaba..b5088d4 100644
--- a/tests/sniffing-test.c
+++ b/tests/sniffing-test.c
@@ -47,12 +47,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
                        g_file_get_contents (SRCDIR "/resources/mbox",
                                             &contents, &length,
                                             &error);
-               }
-
-               if (error) {
-                       g_error ("%s", error->message);
-                       g_error_free (error);
-                       exit (1);
+                       g_assert_no_error (error);
                }
 
                soup_message_headers_append (msg->response_headers,
@@ -66,16 +61,11 @@ server_callback (SoupServer *server, SoupMessage *msg,
                g_file_get_contents (file_name,
                                     &contents, &length,
                                     &error);
+               g_assert_no_error (error);
 
                g_free (base_name);
                g_free (file_name);
 
-               if (error) {
-                       g_error ("%s", error->message);
-                       g_error_free (error);
-                       exit (1);
-               }
-
                soup_message_headers_append (msg->response_headers,
                                             "Content-Type", "text/plain");
        }
@@ -87,16 +77,11 @@ server_callback (SoupServer *server, SoupMessage *msg,
                g_file_get_contents (file_name,
                                     &contents, &length,
                                     &error);
+               g_assert_no_error (error);
 
                g_free (base_name);
                g_free (file_name);
 
-               if (error) {
-                       g_error ("%s", error->message);
-                       g_error_free (error);
-                       exit (1);
-               }
-
                soup_message_headers_append (msg->response_headers,
                                             "Content-Type", "UNKNOWN/unknown");
        }
@@ -111,16 +96,11 @@ server_callback (SoupServer *server, SoupMessage *msg,
                g_file_get_contents (file_name,
                                     &contents, &length,
                                     &error);
+               g_assert_no_error (error);
 
                g_free (base_name);
                g_free (file_name);
 
-               if (error) {
-                       g_error ("%s", error->message);
-                       g_error_free (error);
-                       exit (1);
-               }
-
                /* Hack to allow passing type in the URI */
                ptr = g_strrstr (components[2], "_");
                *ptr = '/';
@@ -137,16 +117,11 @@ server_callback (SoupServer *server, SoupMessage *msg,
                g_file_get_contents (file_name,
                                     &contents, &length,
                                     &error);
+               g_assert_no_error (error);
 
                g_free (base_name);
                g_free (file_name);
 
-               if (error) {
-                       g_error ("%s", error->message);
-                       g_error_free (error);
-                       exit (1);
-               }
-
                soup_message_headers_append (msg->response_headers,
                                             "Content-Type", "text/xml");
                soup_message_headers_append (msg->response_headers,
@@ -181,10 +156,8 @@ content_sniffed (SoupMessage *msg, char *content_type, GHashTable *params, gpoin
 
        debug_printf (2, "  content-sniffed -> %s\n", content_type);
 
-       if (g_object_get_data (G_OBJECT (msg), "got-chunk")) {
-               debug_printf (1, "  got-chunk got emitted before content-sniffed\n");
-               errors++;
-       }
+       soup_test_assert (g_object_get_data (G_OBJECT (msg), "got-chunk") == NULL,
+                         "got-chunk got emitted before content-sniffed");
 
        g_object_set_data (G_OBJECT (msg), "content-sniffed", GINT_TO_POINTER (TRUE));
 
@@ -202,10 +175,8 @@ got_headers (SoupMessage *msg, gpointer data)
 
        debug_printf (2, "  got-headers\n");
 
-       if (g_object_get_data (G_OBJECT (msg), "content-sniffed")) {
-               debug_printf (1, "  content-sniffed got emitted before got-headers\n");
-               errors++;
-       }
+       soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") == NULL,
+                         "content-sniffed got emitted before got-headers");
 
        g_object_set_data (G_OBJECT (msg), "got-headers", GINT_TO_POINTER (TRUE));
 
@@ -277,14 +248,12 @@ do_signals_test (gboolean should_content_sniff,
 
        soup_session_send_message (session, msg);
 
-       if (!should_content_sniff &&
-           g_object_get_data (G_OBJECT (msg), "content-sniffed")) {
-               debug_printf (1, "  content-sniffed got emitted without a sniffer\n");
-               errors++;
-       } else if (should_content_sniff &&
-                  !g_object_get_data (G_OBJECT (msg), "content-sniffed")) {
-               debug_printf (1, "  content-sniffed did not get emitted\n");
-               errors++;
+       if (should_content_sniff) {
+               soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") != NULL,
+                                 "content-sniffed did not get emitted");
+       } else {
+               soup_test_assert (g_object_get_data (G_OBJECT (msg), "content-sniffed") == NULL,
+                                 "content-sniffed got emitted without a sniffer");
        }
 
        if (empty_response) {
@@ -294,12 +263,7 @@ do_signals_test (gboolean should_content_sniff,
                g_file_get_contents (SRCDIR "/resources/mbox",
                                     &contents, &length,
                                     &error);
-       }
-
-       if (error) {
-               g_error ("%s", error->message);
-               g_error_free (error);
-               exit (1);
+               g_assert_no_error (error);
        }
 
        if (!should_accumulate && chunk_data)
@@ -307,15 +271,8 @@ do_signals_test (gboolean should_content_sniff,
        else if (msg->response_body)
                body = soup_message_body_flatten (msg->response_body);
 
-       if (body && body->length != length) {
-               debug_printf (1, "  lengths do not match\n");
-               errors++;
-       }
-
-       if (body && memcmp (body->data, contents, length)) {
-               debug_printf (1, "  downloaded data does not match\n");
-               errors++;
-       }
+       if (body)
+               soup_assert_cmpmem (body->data, body->length, contents, length);
 
        g_free (contents);
        if (body)
@@ -330,6 +287,41 @@ do_signals_test (gboolean should_content_sniff,
 }
 
 static void
+do_signals_tests (gconstpointer data)
+{
+       gboolean should_content_sniff = GPOINTER_TO_INT (data);
+
+       if (!should_content_sniff)
+               soup_session_remove_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);
+
+       do_signals_test (should_content_sniff,
+                        FALSE, FALSE, FALSE, FALSE);
+       do_signals_test (should_content_sniff,
+                        FALSE, FALSE, TRUE, FALSE);
+       do_signals_test (should_content_sniff,
+                        FALSE, TRUE, FALSE, FALSE);
+       do_signals_test (should_content_sniff,
+                        FALSE, TRUE, TRUE, FALSE);
+
+       do_signals_test (should_content_sniff,
+                        TRUE, TRUE, FALSE, FALSE);
+       do_signals_test (should_content_sniff,
+                        TRUE, TRUE, TRUE, FALSE);
+       do_signals_test (should_content_sniff,
+                        TRUE, FALSE, FALSE, FALSE);
+       do_signals_test (should_content_sniff,
+                        TRUE, FALSE, TRUE, FALSE);
+
+       do_signals_test (should_content_sniff,
+                        TRUE, TRUE, FALSE, TRUE);
+       do_signals_test (should_content_sniff,
+                        TRUE, TRUE, TRUE, TRUE);
+
+       if (!should_content_sniff)
+               soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);
+}
+
+static void
 sniffing_content_sniffed (SoupMessage *msg, const char *content_type,
                          GHashTable *params, gpointer data)
 {
@@ -360,10 +352,9 @@ test_sniffing (const char *path, const char *expected_type)
        SoupRequest *req;
        GInputStream *stream;
        char *sniffed_type = NULL;
+       const char *req_sniffed_type;
        GError *error = NULL;
 
-       debug_printf (1, "test_sniffing(\"%s\", \"%s\")\n", path, expected_type);
-
        uri = soup_uri_new_with_base (base_uri, path);
        msg = soup_message_new_from_uri ("GET", uri);
 
@@ -371,14 +362,7 @@ test_sniffing (const char *path, const char *expected_type)
                          G_CALLBACK (sniffing_content_sniffed), &sniffed_type);
 
        soup_session_send_message (session, msg);
-       if (!sniffed_type) {
-               debug_printf (1, "  message was not sniffed!\n");
-               errors++;
-       } else if (strcmp (sniffed_type, expected_type) != 0) {
-               debug_printf (1, "  message sniffing failed! expected %s, got %s\n",
-                             expected_type, sniffed_type);
-               errors++;
-       }
+       g_assert_cmpstr (sniffed_type, ==, expected_type);
        g_free (sniffed_type);
        g_object_unref (msg);
 
@@ -388,32 +372,39 @@ test_sniffing (const char *path, const char *expected_type)
                soup_test_request_close_stream (req, stream, NULL, &error);
                g_object_unref (stream);
        }
-       if (error) {
-               debug_printf (1, "  request failed: %s\n", error->message);
-               g_clear_error (&error);
-       } else {
-               const char *req_sniffed_type;
+       g_assert_no_error (error);
+       g_clear_error (&error);
 
-               req_sniffed_type = soup_request_get_content_type (req);
-               if (strcmp (req_sniffed_type, expected_type) != 0) {
-                       debug_printf (1, "  request sniffing failed! expected %s, got %s\n",
-                                     expected_type, req_sniffed_type);
-                       errors++;
-               }
-       }
+       req_sniffed_type = soup_request_get_content_type (req);
+       g_assert_cmpstr (req_sniffed_type, ==, expected_type);
        g_object_unref (req);
 
        soup_uri_free (uri);
 }
 
 static void
-test_disabled (const char *path)
+do_sniffing_test (gconstpointer data)
 {
+       const char *path_and_result = data;
+       char **parts;
+
+       parts = g_strsplit (path_and_result, " => ", -1);
+       g_assert (parts && parts[0] && parts[1] && !parts[2]);
+
+       test_sniffing (parts[0], parts[1]);
+       g_strfreev (parts);
+}
+
+static void
+test_disabled (gconstpointer data)
+{
+       const char *path = data;
        SoupURI *uri;
        SoupMessage *msg;
        SoupRequest *req;
        GInputStream *stream;
        char *sniffed_type = NULL;
+       const char *sniffed_content_type;
        GError *error = NULL;
 
        debug_printf (1, "test_disabled(\"%s\")\n", path);
@@ -428,11 +419,7 @@ test_disabled (const char *path)
 
        soup_session_send_message (session, msg);
 
-       if (sniffed_type) {
-               debug_printf (1, "  message was sniffed!\n");
-               errors++;
-               g_free (sniffed_type);
-       }
+       g_assert_null (sniffed_type);
        g_object_unref (msg);
 
        req = soup_session_request_uri (session, uri, NULL);
@@ -444,18 +431,11 @@ test_disabled (const char *path)
                soup_test_request_close_stream (req, stream, NULL, &error);
                g_object_unref (stream);
        }
-       if (error) {
-               debug_printf (1, "  request failed: %s\n", error->message);
-               g_clear_error (&error);
-       } else {
-               const char *sniffed_content_type;
+       g_assert_no_error (error);
+
+       sniffed_content_type = soup_request_get_content_type (req);
+       g_assert_cmpstr (sniffed_content_type, ==, NULL);
 
-               sniffed_content_type = soup_request_get_content_type (req);
-               if (sniffed_content_type != NULL) {
-                       debug_printf (1, "  request was sniffed!\n");
-                       errors++;
-               }
-       }
        g_object_unref (req);
 
        soup_uri_free (uri);
@@ -465,6 +445,7 @@ int
 main (int argc, char **argv)
 {
        SoupServer *server;
+       int ret;
 
        test_init (argc, argv, NULL);
 
@@ -476,106 +457,113 @@ main (int argc, char **argv)
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                         SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
                                         NULL);
-
-       /* No sniffer, no content_sniffed should be emitted */
-       do_signals_test (FALSE, FALSE, FALSE, FALSE, FALSE);
-       do_signals_test (FALSE, FALSE, FALSE, TRUE, FALSE);
-       do_signals_test (FALSE, FALSE, TRUE, FALSE, FALSE);
-       do_signals_test (FALSE, FALSE, TRUE, TRUE, FALSE);
-
-       do_signals_test (FALSE, TRUE, TRUE, FALSE, FALSE);
-       do_signals_test (FALSE, TRUE, TRUE, TRUE, FALSE);
-       do_signals_test (FALSE, TRUE, FALSE, FALSE, FALSE);
-       do_signals_test (FALSE, TRUE, FALSE, TRUE, FALSE);
-
-       /* Tests that the signals are correctly emitted for empty
-        * responses; see
-        * http://bugzilla.gnome.org/show_bug.cgi?id=587907 */
-
-       do_signals_test (FALSE, TRUE, TRUE, FALSE, TRUE);
-       do_signals_test (FALSE, TRUE, TRUE, TRUE, TRUE);
-
        soup_session_add_feature_by_type (session, SOUP_TYPE_CONTENT_SNIFFER);
 
-       /* Now, with a sniffer, content_sniffed must be emitted after
-        * got-headers, and before got-chunk.
-        */
-       do_signals_test (TRUE, FALSE, FALSE, FALSE, FALSE);
-       do_signals_test (TRUE, FALSE, FALSE, TRUE, FALSE);
-       do_signals_test (TRUE, FALSE, TRUE, FALSE, FALSE);
-       do_signals_test (TRUE, FALSE, TRUE, TRUE, FALSE);
-
-       do_signals_test (TRUE, TRUE, TRUE, FALSE, FALSE);
-       do_signals_test (TRUE, TRUE, TRUE, TRUE, FALSE);
-       do_signals_test (TRUE, TRUE, FALSE, FALSE, FALSE);
-       do_signals_test (TRUE, TRUE, FALSE, TRUE, FALSE);
+       g_test_add_data_func ("/sniffing/signals/no-sniffer",
+                             GINT_TO_POINTER (FALSE),
+                             do_signals_tests);
+       g_test_add_data_func ("/sniffing/signals/with-sniffer",
+                             GINT_TO_POINTER (TRUE),
+                             do_signals_tests);
 
-       /* Empty response tests */
-       do_signals_test (TRUE, TRUE, TRUE, FALSE, TRUE);
-       do_signals_test (TRUE, TRUE, TRUE, TRUE, TRUE);
-
-       /* Test the text_or_binary sniffing path */
-
-       /* GIF is a 'safe' type */
-       test_sniffing ("/text_or_binary/home.gif", "image/gif");
+       g_test_add_data_func ("/sniffing/type/gif",
+                             "text_or_binary/home.gif => image/gif",
+                             do_sniffing_test);
 
        /* With our current code, no sniffing is done using GIO, so
         * the mbox will be identified as text/plain; should we change
         * this?
         */
-       test_sniffing ("/text_or_binary/mbox", "text/plain");
+       g_test_add_data_func ("/sniffing/type/mbox",
+                             "text_or_binary/mbox => text/plain",
+                             do_sniffing_test);
 
        /* HTML is considered unsafe for this algorithm, since it is
         * scriptable, so going from text/plain to text/html is
         * considered 'privilege escalation'
         */
-       test_sniffing ("/text_or_binary/test.html", "text/plain");
+       g_test_add_data_func ("/sniffing/type/html-in-text-context",
+                             "text_or_binary/test.html => text/plain",
+                             do_sniffing_test);
 
        /* text/plain with binary content and unknown pattern should be
-        * application/octet-stream */
-       test_sniffing ("/text_or_binary/text_binary.txt", "application/octet-stream");
+        * application/octet-stream
+        */
+       g_test_add_data_func ("/sniffing/type/text-binary",
+                             "text_or_binary/text_binary.txt => application/octet-stream",
+                             do_sniffing_test);
 
-       /* text/plain with binary content and scriptable pattern should be
-        * application/octet-stream to avoid 'privilege escalation' */
-       test_sniffing ("/text_or_binary/html_binary.html", "application/octet-stream");
+       /* text/html with binary content and scriptable pattern should be
+        * application/octet-stream to avoid 'privilege escalation'
+        */
+       g_test_add_data_func ("/sniffing/type/html-binary",
+                             "text_or_binary/html_binary.html => application/octet-stream",
+                             do_sniffing_test);
 
        /* text/plain with binary content and non scriptable known pattern should
-        * be the given type */
-       test_sniffing ("/text_or_binary/ps_binary.ps", "application/postscript");
+        * be the given type
+        */
+       g_test_add_data_func ("/sniffing/type/ps",
+                             "text_or_binary/ps_binary.ps => application/postscript",
+                             do_sniffing_test);
 
        /* Test the unknown sniffing path */
-
-       test_sniffing ("/unknown/test.html", "text/html");
-       test_sniffing ("/unknown/home.gif", "image/gif");
-       test_sniffing ("/unknown/mbox", "text/plain");
-       test_sniffing ("/unknown/text_binary.txt", "application/octet-stream");
+       g_test_add_data_func ("/sniffing/type/unknown-html",
+                             "unknown/test.html => text/html",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/unknown-gif",
+                             "unknown/home.gif => image/gif",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/unknown-mbox",
+                             "unknown/mbox => text/plain",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/unknown-binary",
+                             "unknown/text_binary.txt => application/octet-stream",
+                             do_sniffing_test);
 
        /* Test the XML sniffing path */
-
-       test_sniffing ("/type/text_xml/home.gif", "text/xml");
-       test_sniffing ("/type/anice_type+xml/home.gif", "anice/type+xml");
-       test_sniffing ("/type/application_xml/home.gif", "application/xml");
+       g_test_add_data_func ("/sniffing/type/xml",
+                             "type/text_xml/home.gif => text/xml",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/xml+xml",
+                             "type/anice_type+xml/home.gif => anice/type+xml",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/application-xml",
+                             "type/application_xml/home.gif => application/xml",
+                             do_sniffing_test);
 
        /* Test the image sniffing path */
-
-       test_sniffing ("/type/image_png/home.gif", "image/gif");
+       g_test_add_data_func ("/sniffing/type/image",
+                             "type/image_png/home.gif => image/gif",
+                             do_sniffing_test);
 
        /* Test the feed or html path */
-
-       test_sniffing ("/type/text_html/test.html", "text/html");
-       test_sniffing ("/type/text_html/rss20.xml", "application/rss+xml");
-       test_sniffing ("/type/text_html/atom.xml", "application/atom+xml");
+       g_test_add_data_func ("/sniffing/type/html/html",
+                             "type/text_html/test.html => text/html",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/html/rss",
+                             "type/text_html/rss20.xml => application/rss+xml",
+                             do_sniffing_test);
+       g_test_add_data_func ("/sniffing/type/html/atom",
+                             "type/text_html/atom.xml => application/atom+xml",
+                             do_sniffing_test);
 
        /* The spec tells us to only use the last Content-Type header */
-
-       test_sniffing ("/multiple_headers/home.gif", "image/gif");
+       g_test_add_data_func ("/sniffing/multiple-headers",
+                             "multiple_headers/home.gif => image/gif",
+                             do_sniffing_test);
 
        /* Test that we keep the parameters when sniffing */
-       test_sniffing ("/type/text_html; charset=UTF-8/test.html", "text/html; charset=UTF-8");
+       g_test_add_data_func ("/sniffing/parameters",
+                             "type/text_html; charset=UTF-8/test.html => text/html; charset=UTF-8",
+                             do_sniffing_test);
 
        /* Test that disabling the sniffer works correctly */
+       g_test_add_data_func ("/sniffing/disabled",
+                             "/text_or_binary/home.gif",
+                             test_disabled);
 
-       test_disabled ("/text_or_binary/home.gif");
+       ret = g_test_run ();
 
        soup_uri_free (base_uri);
 
@@ -583,5 +571,5 @@ main (int argc, char **argv)
        soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/socket-test.c b/tests/socket-test.c
index 42ab6c8..4fb0d35 100644
--- a/tests/socket-test.c
+++ b/tests/socket-test.c
@@ -24,75 +24,82 @@ do_unconnected_socket_test (void)
 
        localhost = soup_address_new_from_sockaddr (
                (struct sockaddr *) &in_localhost, sizeof (in_localhost));
-       g_assert (localhost != NULL);
+       g_assert_true (localhost != NULL);
        res = soup_address_resolve_sync (localhost, NULL);
        g_assert_cmpuint (res, ==, SOUP_STATUS_OK);
 
-       sock = soup_socket_new (
-               SOUP_SOCKET_LOCAL_ADDRESS, localhost,
-               NULL);
-       g_assert (sock != NULL);
+       sock = soup_socket_new (SOUP_SOCKET_LOCAL_ADDRESS, localhost,
+                               NULL);
+       g_assert_true (sock != NULL);
 
        addr = soup_socket_get_local_address (sock);
-       g_assert (addr != NULL);
+       g_assert_true (addr != NULL);
        g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
        g_assert_cmpuint (soup_address_get_port (addr), ==, 0);
 
        /* fails with ENOTCONN */
-       expect_warning++;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*socket not connected*");
        addr = soup_socket_get_remote_address (sock);
-       g_assert (addr == NULL);
+       g_test_assert_expected_messages ();
+       g_assert_null (addr);
 
        res = soup_socket_listen (sock);
-       g_assert_cmpuint (res, ==, TRUE);
+       g_assert_true (res);
 
        addr = soup_socket_get_local_address (sock);
-       g_assert (addr != NULL);
+       g_assert_true (addr != NULL);
        g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
        g_assert_cmpuint (soup_address_get_port (addr), >, 0);
 
-       client = soup_socket_new (
-               SOUP_SOCKET_REMOTE_ADDRESS,
-                       soup_socket_get_local_address (sock),
-               NULL);
+       client = soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS,
+                                 soup_socket_get_local_address (sock),
+                                 NULL);
        res = soup_socket_connect_sync (client, NULL);
        g_assert_cmpuint (res, ==, SOUP_STATUS_OK);
        addr = soup_socket_get_local_address (client);
-       g_assert (addr != NULL);
+       g_assert_true (addr != NULL);
        addr = soup_socket_get_remote_address (client);
-       g_assert (addr != NULL);
+       g_assert_true (addr != NULL);
        g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
        g_assert_cmpuint (soup_address_get_port (addr), >, 0);
        g_object_unref (client);
 
-       client = soup_socket_new (
-               SOUP_SOCKET_REMOTE_ADDRESS,
-                       soup_socket_get_local_address (sock),
-               NULL);
+       client = soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS,
+                                 soup_socket_get_local_address (sock),
+                                 NULL);
        /* save it for later */
 
        /* listening socket fails with ENOTCONN */
-       expect_warning++;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*endpoint is not connected*");
        addr = soup_socket_get_remote_address (sock);
-       g_assert (addr == NULL);
+       g_test_assert_expected_messages ();
+       g_assert_null (addr);
 
        soup_socket_disconnect (sock);
 
-       expect_warning++;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*socket not connected*");
        addr = soup_socket_get_remote_address (sock);
-       g_assert (addr == NULL);
+       g_test_assert_expected_messages ();
+       g_assert_null (addr);
 
        /* has never been connected */
-       expect_warning++;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*socket not connected*");
        addr = soup_socket_get_local_address (client);
-       g_assert (addr == NULL);
+       g_test_assert_expected_messages ();
+       g_assert_null (addr);
 
        res = soup_socket_connect_sync (client, NULL);
        g_assert_cmpuint (res, ==, SOUP_STATUS_CANT_CONNECT);
 
-       expect_warning++;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*socket not connected*");
        addr = soup_socket_get_local_address (client);
-       g_assert (addr == NULL);
+       g_test_assert_expected_messages ();
+       g_assert_null (addr);
 
        g_object_unref (localhost);
        g_object_unref (client);
@@ -102,10 +109,14 @@ do_unconnected_socket_test (void)
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, NULL);
 
-       do_unconnected_socket_test ();
+       g_test_add_func ("/sockets/unconnected", do_unconnected_socket_test);
+
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/ssl-test.c b/tests/ssl-test.c
index 7716f30..5ef4129 100644
--- a/tests/ssl-test.c
+++ b/tests/ssl-test.c
@@ -3,7 +3,7 @@
 #include "test-utils.h"
 
 static void
-do_properties_test_for_session (SoupSession *session, char *uri)
+do_properties_test_for_session (SoupSession *session, const char *uri)
 {
        SoupMessage *msg;
        GTlsCertificate *cert;
@@ -11,42 +11,23 @@ do_properties_test_for_session (SoupSession *session, char *uri)
 
        msg = soup_message_new ("GET", uri);
        soup_session_send_message (session, msg);
-       if (msg->status_code != SOUP_STATUS_OK) {
-               debug_printf (1, "    FAILED: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        if (soup_message_get_https_status (msg, &cert, &flags)) {
-               if (!G_IS_TLS_CERTIFICATE (cert)) {
-                       debug_printf (1, "    No certificate?\n");
-                       errors++;
-               }
-               if (flags != G_TLS_CERTIFICATE_UNKNOWN_CA) {
-                       debug_printf (1, "    Wrong cert flags (got %x, wanted %x)\n",
-                                     flags, G_TLS_CERTIFICATE_UNKNOWN_CA);
-                       errors++;
-               }
-       } else {
-               debug_printf (1, "    Response not https\n");
-               errors++;
-       }
-       if (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED) {
-               debug_printf (1, "    CERTIFICATE_TRUSTED set?\n");
-               errors++;
-       }
+               g_assert_true (G_IS_TLS_CERTIFICATE (cert));
+               g_assert_cmpuint (flags, ==, G_TLS_CERTIFICATE_UNKNOWN_CA);
+       } else
+               soup_test_assert (FALSE, "Response not https");
+       g_assert_false (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED);
 
        g_object_unref (msg);
 }
 
 static void
-do_properties_tests (char *uri)
+do_async_properties_tests (gconstpointer uri)
 {
        SoupSession *session;
 
-       debug_printf (1, "\nSoupMessage properties\n");
-
-       debug_printf (1, "  async\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
        g_object_set (G_OBJECT (session),
                      SOUP_SESSION_SSL_CA_FILE, "/dev/null",
@@ -54,8 +35,13 @@ do_properties_tests (char *uri)
                      NULL);
        do_properties_test_for_session (session, uri);
        soup_test_session_abort_unref (session);
+}
+
+static void
+do_sync_properties_tests (gconstpointer uri)
+{
+       SoupSession *session;
 
-       debug_printf (1, "  sync\n");
        session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
        g_object_set (G_OBJECT (session),
                      SOUP_SESSION_SSL_CA_FILE, "/dev/null",
@@ -66,7 +52,7 @@ do_properties_tests (char *uri)
 }
 
 static void
-do_one_strict_test (SoupSession *session, char *uri,
+do_one_strict_test (SoupSession *session, const char *uri,
                    gboolean strict, gboolean with_ca_list,
                    guint expected_status)
 {
@@ -97,28 +83,18 @@ do_one_strict_test (SoupSession *session, char *uri,
                        soup_message_get_https_status (msg, NULL, &flags);
                        debug_printf (1, "              tls error flags: 0x%x\n", flags);
                }
-               errors++;
-       } else if (with_ca_list && SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               if (!(soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED)) {
-                       debug_printf (1, "    CERTIFICATE_TRUSTED not set?\n");
-                       errors++;
-               }
-       } else {
-               if (with_ca_list && soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED) {
-                       debug_printf (1, "    CERTIFICATE_TRUSTED set?\n");
-                       errors++;
-               }
-       }
-       if (!soup_message_get_https_status (msg, NULL, NULL)) {
-               debug_printf (1, "      get_https_status returns FALSE?\n");
-               errors++;
-       }
+       } else if (with_ca_list && SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
+               g_assert_true (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED);
+       else
+               g_assert_false (soup_message_get_flags (msg) & SOUP_MESSAGE_CERTIFICATE_TRUSTED);
+
+       g_assert_true (soup_message_get_https_status (msg, NULL, NULL));
 
        g_object_unref (msg);
 }
 
 static void
-do_strict_tests (char *uri)
+do_strict_tests (gconstpointer uri)
 {
        SoupSession *session;
 
@@ -179,20 +155,12 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (use_system) {
-               debug_printf (1, "  ssl-use-system-ca-file defaults to TRUE?\n");
-               errors++;
-       }
-       if (tlsdb) {
-               debug_printf (1, "  tls-database set by default?\n");
-               errors++;
-               g_object_unref (tlsdb);
-       }
-       if (ca_file) {
-               debug_printf (1, "  ca-file set by default?\n");
-               errors++;
-               g_free (ca_file);
-       }
+       soup_test_assert (!use_system,
+                         "ssl-use-system-ca-file defaults to TRUE");
+       soup_test_assert (tlsdb == NULL,
+                         "tls-database set by default");
+       soup_test_assert (ca_file == NULL,
+                         "ca-file set by default");
 
        use_system_changed = tlsdb_changed = ca_file_changed = FALSE;
        g_object_set (G_OBJECT (session),
@@ -203,32 +171,16 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (!use_system) {
-               debug_printf (1, "  setting ssl-use-system-ca-file failed\n");
-               errors++;
-       }
-       if (!tlsdb) {
-               debug_printf (1, "  setting ssl-use-system-ca-file didn't set tls-database\n");
-               errors++;
-       } else
-               g_object_unref (tlsdb);
-       if (ca_file) {
-               debug_printf (1, "  setting ssl-use-system-ca-file set ssl-ca-file\n");
-               errors++;
-               g_free (ca_file);
-       }
-       if (!use_system_changed) {
-               debug_printf (1, "  setting ssl-use-system-ca-file didn't emit 
notify::ssl-use-system-ca-file\n");
-               errors++;
-       }
-       if (!tlsdb_changed) {
-               debug_printf (1, "  setting ssl-use-system-ca-file didn't emit notify::tls-database\n");
-               errors++;
-       }
-       if (ca_file_changed) {
-               debug_printf (1, "  setting ssl-use-system-ca-file emitted notify::ssl-ca-file\n");
-               errors++;
-       }
+       soup_test_assert (use_system,
+                         "setting ssl-use-system-ca-file failed");
+       g_assert_true (use_system_changed);
+       soup_test_assert (tlsdb != NULL,
+                         "setting ssl-use-system-ca-file didn't set tls-database");
+       g_assert_true (tlsdb_changed);
+       g_clear_object (&tlsdb);
+       soup_test_assert (ca_file == NULL,
+                         "setting ssl-use-system-ca-file set ssl-ca-file");
+       g_assert_false (ca_file_changed);
 
        use_system_changed = tlsdb_changed = ca_file_changed = FALSE;
        g_object_set (G_OBJECT (session),
@@ -239,32 +191,17 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (use_system) {
-               debug_printf (1, "  setting ssl-ca-file left ssl-use-system-ca-file set\n");
-               errors++;
-       }
-       if (!tlsdb) {
-               debug_printf (1, "  setting ssl-ca-file didn't set tls-database\n");
-               errors++;
-       } else
-               g_object_unref (tlsdb);
-       if (!ca_file) {
-               debug_printf (1, "  setting ssl-ca-file failed\n");
-               errors++;
-       } else
-               g_free (ca_file);
-       if (!use_system_changed) {
-               debug_printf (1, "  setting ssl-ca-file didn't emit notify::ssl-use-system-ca-file\n");
-               errors++;
-       }
-       if (!tlsdb_changed) {
-               debug_printf (1, "  setting ssl-ca-file didn't emit notify::tls-database\n");
-               errors++;
-       }
-       if (!ca_file_changed) {
-               debug_printf (1, "  setting ssl-ca-file didn't emit notify::ssl-ca-file\n");
-               errors++;
-       }
+       soup_test_assert (!use_system,
+                         "setting ssl-ca-file left ssl-use-system-ca-file set");
+       g_assert_true (use_system_changed);
+       soup_test_assert (tlsdb != NULL,
+                         "setting ssl-ca-file didn't set tls-database");
+       g_assert_true (tlsdb_changed);
+       g_clear_object (&tlsdb);
+       soup_test_assert (ca_file != NULL,
+                         "setting ssl-ca-file failed");
+       g_assert_true (ca_file_changed);
+       g_free (ca_file);
 
        use_system_changed = tlsdb_changed = ca_file_changed = FALSE;
        g_object_set (G_OBJECT (session),
@@ -275,32 +212,15 @@ do_session_property_tests (void)
                      "tls-database", &tlsdb,
                      "ssl-ca-file", &ca_file,
                      NULL);
-       if (use_system) {
-               debug_printf (1, "  setting tls-database NULL left ssl-use-system-ca-file set\n");
-               errors++;
-       }
-       if (tlsdb) {
-               debug_printf (1, "  setting tls-database NULL failed\n");
-               errors++;
-               g_object_unref (tlsdb);
-       }
-       if (ca_file) {
-               debug_printf (1, "  setting tls-database didn't clear ssl-ca-file\n");
-               errors++;
-               g_free (ca_file);
-       }
-       if (use_system_changed) {
-               debug_printf (1, "  setting tls-database emitted notify::ssl-use-system-ca-file\n");
-               errors++;
-       }
-       if (!tlsdb_changed) {
-               debug_printf (1, "  setting tls-database didn't emit notify::tls-database\n");
-               errors++;
-       }
-       if (!ca_file_changed) {
-               debug_printf (1, "  setting tls-database didn't emit notify::ssl-ca-file\n");
-               errors++;
-       }
+       soup_test_assert (!use_system,
+                         "setting tls-database NULL left ssl-use-system-ca-file set");
+       g_assert_false (use_system_changed);
+       soup_test_assert (tlsdb == NULL,
+                         "setting tls-database NULL failed");
+       g_assert_true (tlsdb_changed);
+       soup_test_assert (ca_file == NULL,
+                         "setting tls-database didn't clear ssl-ca-file");
+       g_assert_true (ca_file_changed);
 
        soup_test_session_abort_unref (session);
 }
@@ -324,23 +244,32 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        char *uri;
+       int ret;
 
        test_init (argc, argv, NULL);
 
-       if (tls_available) {
-               server = soup_test_server_new_ssl (TRUE);
-               soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
-               uri = g_strdup_printf ("https://127.0.0.1:%u/";,
-                                      soup_server_get_port (server));
+       if (!tls_available) {
+               test_cleanup ();
+               return 77; /* SKIP */
+       }
 
-               do_session_property_tests ();
-               do_strict_tests (uri);
-               do_properties_tests (uri);
+       server = soup_test_server_new_ssl (TRUE);
+       soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
+       uri = g_strdup_printf ("https://127.0.0.1:%u/";,
+                              soup_server_get_port (server));
 
-               g_free (uri);
-               soup_test_server_quit_unref (server);
-       }
+       g_test_add_func ("/ssl/session-properties", do_session_property_tests);
+       g_test_add_data_func ("/ssl/message-properties/async", uri, do_async_properties_tests);
+       g_test_add_data_func ("/ssl/message-properties/sync", uri, do_sync_properties_tests);
+
+       /* FIXME: split this up */
+       g_test_add_data_func ("/ssl/strict", uri, do_strict_tests);
+
+       ret = g_test_run ();
+
+       g_free (uri);
+       soup_test_server_quit_unref (server);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/streaming-test.c b/tests/streaming-test.c
index 239e0ce..9790766 100644
--- a/tests/streaming-test.c
+++ b/tests/streaming-test.c
@@ -106,44 +106,47 @@ do_request (SoupSession *session, SoupURI *base_uri, char *path)
 
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "  message failed: %d %s\n",
-                             msg->status_code, msg->reason_phrase);
-               errors++;
-       }
-
-       if (msg->response_body->length != full_response_length) {
-               debug_printf (1, "  received length mismatch: expected %d, got %d\n",
-                             (int)full_response_length, (int)msg->request_body->length);
-               errors++;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
+       g_assert_cmpint (msg->response_body->length, ==, full_response_length);
 
        md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
                                           (guchar *)msg->response_body->data,
                                           msg->response_body->length);
-       if (strcmp (md5, full_response_md5) != 0) {
-               debug_printf (1, "  data mismatch: expected %s, got %s\n",
-                             full_response_md5, md5);
-               errors++;
-       }
+       g_assert_cmpstr (md5, ==, full_response_md5);
        g_free (md5);
 
        g_object_unref (msg);
 }
 
 static void
-do_tests (SoupURI *base_uri)
+do_chunked_test (gconstpointer data)
 {
+       SoupURI *base_uri = (SoupURI *)data;
        SoupSession *session;
 
        session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
-       debug_printf (1, "Chunked encoding\n");
        do_request (session, base_uri, "chunked");
-       debug_printf (1, "\n");
-       debug_printf (1, "Content-Length encoding\n");
+       soup_test_session_abort_unref (session);
+}
+
+static void
+do_content_length_test (gconstpointer data)
+{
+       SoupURI *base_uri = (SoupURI *)data;
+       SoupSession *session;
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
        do_request (session, base_uri, "content-length");
-       debug_printf (1, "\n");
-       debug_printf (1, "EOF encoding\n");
+       soup_test_session_abort_unref (session);
+}
+
+static void
+do_eof_test (gconstpointer data)
+{
+       SoupURI *base_uri = (SoupURI *)data;
+       SoupSession *session;
+
+       session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
        do_request (session, base_uri, "eof");
        soup_test_session_abort_unref (session);
 }
@@ -155,8 +158,10 @@ main (int argc, char **argv)
        SoupServer *server;
        guint port;
        SoupURI *base_uri;
+       int ret;
 
        test_init (argc, argv, NULL);
+
        get_full_response ();
 
        server = soup_test_server_new (FALSE);
@@ -168,14 +173,20 @@ main (int argc, char **argv)
 
        base_uri = soup_uri_new ("http://127.0.0.1";);
        soup_uri_set_port (base_uri, port);
-       do_tests (base_uri);
-       soup_uri_free (base_uri);
 
+       g_test_add_data_func ("/streaming/chunked", base_uri, do_chunked_test);
+       g_test_add_data_func ("/streaming/content-length", base_uri, do_content_length_test);
+       g_test_add_data_func ("/streaming/eof", base_uri, do_eof_test);
+
+       ret = g_test_run ();
+
+       soup_uri_free (base_uri);
        g_main_loop_unref (loop);
 
        g_free (full_response);
        g_free (full_response_md5);
        soup_test_server_quit_unref (server);
        test_cleanup ();
-       return errors != 0;
+
+       return ret;
 }
diff --git a/tests/test-utils.c b/tests/test-utils.c
index 36b0ee5..c28994a 100644
--- a/tests/test-utils.c
+++ b/tests/test-utils.c
@@ -13,8 +13,7 @@ static gboolean apache_running;
 
 static SoupLogger *logger;
 
-int debug_level, errors;
-gboolean parallelize = TRUE;
+int debug_level;
 gboolean expect_warning, tls_available;
 static int http_debug_level;
 
@@ -38,9 +37,6 @@ static GOptionEntry debug_entry[] = {
        { "debug", 'd', G_OPTION_FLAG_NO_ARG,
          G_OPTION_ARG_CALLBACK, increment_debug_level,
          "Enable (or increase) test-specific debugging", NULL },
-       { "parallel", 'p', G_OPTION_FLAG_REVERSE,
-         G_OPTION_ARG_NONE, &parallelize,
-         "Toggle parallelization (default is on, unless -d or -h)", NULL },
        { "http-debug", 'h', G_OPTION_FLAG_NO_ARG,
          G_OPTION_ARG_CALLBACK, increment_http_debug_level,
          "Enable (or increase) HTTP-level debugging", NULL },
@@ -58,21 +54,6 @@ quit (int sig)
        exit (1);
 }
 
-static void
-test_log_handler (const char *log_domain, GLogLevelFlags log_level,
-                 const char *message, gpointer user_data)
-{
-       if (log_level & (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL)) {
-               if (expect_warning) {
-                       expect_warning = FALSE;
-                       debug_printf (2, "Got expected warning: %s\n", message);
-                       return;
-               } else
-                       errors++;
-       }
-       g_log_default_handler (log_domain, log_level, message, user_data);
-}
-
 void
 test_init (int argc, char **argv, GOptionEntry *entries)
 {
@@ -92,6 +73,9 @@ test_init (int argc, char **argv, GOptionEntry *entries)
                name += 3;
        g_set_prgname (name);
 
+       g_test_init (&argc, &argv, NULL);
+       g_test_set_nonfatal_assertions ();
+
        opts = g_option_context_new (NULL);
        g_option_context_add_main_entries (opts, debug_entry, NULL);
        if (entries)
@@ -106,17 +90,12 @@ test_init (int argc, char **argv, GOptionEntry *entries)
        }
        g_option_context_free (opts);
 
-       if (debug_level > 0 || http_debug_level > 0)
-               parallelize = !parallelize;
-
        if (g_getenv ("SOUP_TESTS_IN_MAKE_CHECK"))
                debug_level = G_MAXINT;
 
        /* Exit cleanly on ^C in case we're valgrinding. */
        signal (SIGINT, quit);
 
-       g_log_set_default_handler (test_log_handler, NULL);
-
        tls_backend = g_tls_backend_get_default ();
        tls_available = g_tls_backend_supports_tls (tls_backend);
 }
@@ -135,12 +114,6 @@ test_cleanup (void)
        g_main_context_unref (g_main_context_default ());
 
        debug_printf (1, "\n");
-       if (errors) {
-               g_print ("%s: %d error(s).%s\n",
-                        g_get_prgname (), errors,
-                        debug_level == 0 ? " Run with '-d' for details" : "");
-       } else
-               g_print ("%s: OK\n", g_get_prgname ());
 }
 
 void
@@ -257,16 +230,10 @@ soup_test_session_new (GType type, ...)
 void
 soup_test_session_abort_unref (SoupSession *session)
 {
-       g_object_add_weak_pointer (G_OBJECT (session), (gpointer *)&session);
-
        soup_session_abort (session);
-       g_object_unref (session);
 
-       if (session) {
-               errors++;
-               debug_printf (1, "leaked SoupSession!\n");
-               g_object_remove_weak_pointer (G_OBJECT (session), (gpointer *)&session);
-       }
+       g_assert_cmpint (G_OBJECT (session)->ref_count, ==, 1);
+       g_object_unref (session);
 }
 
 static gpointer run_server_thread (gpointer user_data);
@@ -348,9 +315,6 @@ soup_test_server_quit_unref (SoupServer *server)
 {
        GThread *thread;
 
-       g_object_add_weak_pointer (G_OBJECT (server),
-                                  (gpointer *)&server);
-
        thread = g_object_get_data (G_OBJECT (server), "thread");
        if (thread) {
                soup_add_completion (soup_server_get_async_context (server),
@@ -358,14 +322,9 @@ soup_test_server_quit_unref (SoupServer *server)
                g_thread_join (thread);
        } else
                soup_server_quit (server);
-       g_object_unref (server);
 
-       if (server) {
-               errors++;
-               debug_printf (1, "leaked SoupServer!\n");
-               g_object_remove_weak_pointer (G_OBJECT (server),
-                                             (gpointer *)&server);
-       }
+       g_assert_cmpint (G_OBJECT (server)->ref_count, ==, 1);
+       g_object_unref (server);
 }
 
 typedef struct {
@@ -554,3 +513,23 @@ soup_test_request_close_stream (SoupRequest   *req,
 
        return ok;
 }
+
+#ifndef G_HAVE_ISO_VARARGS
+void
+soup_test_assert (gboolean expr, const char *fmt, ...)
+{
+       char *message;
+       va_list args;
+
+       if (G_UNLIKELY (!expr)) {
+               va_start (args, fmt);
+               message = g_strdup_vprintf (fmt, args);
+               va_end (args);
+
+               g_assertion_message (G_LOG_DOMAIN,
+                                    "???", 0, "???"
+                                    message);
+               g_free (message);
+       }
+}
+#endif
diff --git a/tests/test-utils.h b/tests/test-utils.h
index c85103d..9774151 100644
--- a/tests/test-utils.h
+++ b/tests/test-utils.h
@@ -1,3 +1,5 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -13,9 +15,8 @@
 void test_init    (int argc, char **argv, GOptionEntry *entries);
 void test_cleanup (void);
 
-extern int debug_level, errors;
-extern gboolean parallelize;
-extern gboolean expect_warning, tls_available;
+extern int debug_level;
+extern gboolean tls_available;
 void debug_printf (int level, const char *format, ...) G_GNUC_PRINTF (2, 3);
 
 #ifdef HAVE_APACHE
@@ -24,13 +25,13 @@ void apache_cleanup (void);
 #endif
 
 typedef enum {
-  SOUP_TEST_REQUEST_NONE = 0,
-  SOUP_TEST_REQUEST_CANCEL_MESSAGE = (1 << 0),
-  SOUP_TEST_REQUEST_CANCEL_CANCELLABLE = (1 << 1),
-  SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 2),
-  SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3),
-  SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE = (1 << 4),
-  SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 5),
+       SOUP_TEST_REQUEST_NONE = 0,
+       SOUP_TEST_REQUEST_CANCEL_MESSAGE = (1 << 0),
+       SOUP_TEST_REQUEST_CANCEL_CANCELLABLE = (1 << 1),
+       SOUP_TEST_REQUEST_CANCEL_SOON = (1 << 2),
+       SOUP_TEST_REQUEST_CANCEL_IMMEDIATE = (1 << 3),
+       SOUP_TEST_REQUEST_CANCEL_PREEMPTIVE = (1 << 4),
+       SOUP_TEST_REQUEST_CANCEL_AFTER_SEND_FINISH = (1 << 5),
 } SoupTestRequestFlags;
 
 SoupSession *soup_test_session_new         (GType type, ...);
@@ -52,3 +53,50 @@ gboolean      soup_test_request_close_stream (SoupRequest   *req,
                                              GInputStream  *stream,
                                              GCancellable  *cancellable,
                                              GError       **error);
+
+#ifdef G_HAVE_ISO_VARARGS
+#define soup_test_assert(expr, ...)                            \
+G_STMT_START {                                                         \
+       char *_message;                                                 \
+       if (G_UNLIKELY (!(expr))) {                                     \
+               _message = g_strdup_printf (__VA_ARGS__);               \
+               g_assertion_message (G_LOG_DOMAIN,                      \
+                                    __FILE__, __LINE__, G_STRFUNC,     \
+                                    _message);                         \
+               g_free (_message);                                      \
+       }                                                               \
+} G_STMT_END
+#else
+void soup_test_assert (gboolean expr, const char *fmt, ...);
+#endif
+
+#define soup_test_assert_message_status(msg, status)                   \
+G_STMT_START {                                                         \
+       SoupMessage *_msg = (msg);                                      \
+       guint _status = (status);                                       \
+       char *_message;                                                 \
+                                                                       \
+       if (G_UNLIKELY (_msg->status_code != _status)) {                \
+               _message = g_strdup_printf ("Unexpected status %d %s (expected %d %s)", \
+                                           _msg->status_code, _msg->reason_phrase,     \
+                                           _status, soup_status_get_phrase (_status)); \
+               g_assertion_message (G_LOG_DOMAIN,                      \
+                                    __FILE__, __LINE__, G_STRFUNC,     \
+                                    _message);                         \
+               g_free (_message);                                      \
+       }                                                               \
+} G_STMT_END
+
+#define soup_assert_cmpmem(s1, l1, s2, l2)                             \
+G_STMT_START {                                                         \
+       int __l1 = l1, __l2 = l2;                                       \
+       gconstpointer __s1 = s1, __s2 = s2;                             \
+       if (G_UNLIKELY ((__l1) != (__l2))) {                            \
+               g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+                                           "len(" #s1 ") == len(" #s2 ")", __l1, "==", __l2, \
+                                           'i');                       \
+       } else if (G_UNLIKELY (memcmp (__s1, __s2, __l1) != 0)) {       \
+               g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
+                                    "assertion failed (" #s1 " == " #s2 ")"); \
+       }                                                               \
+} G_STMT_END
diff --git a/tests/timeout-test.c b/tests/timeout-test.c
index 5903069..fba515d 100644
--- a/tests/timeout-test.c
+++ b/tests/timeout-test.c
@@ -2,6 +2,8 @@
 
 #include "test-utils.h"
 
+static gboolean slow_https;
+
 static void
 message_finished (SoupMessage *msg, gpointer user_data)
 {
@@ -34,24 +36,10 @@ do_message_to_session (SoupSession *session, const char *uri,
                          G_CALLBACK (message_finished), &finished);
        soup_session_send_message (session, msg);
 
-       if (msg->status_code != expected_status) {
-               debug_printf (1, "      FAILED: %d %s (expected %d %s)\n",
-                             msg->status_code, msg->reason_phrase,
-                             expected_status,
-                             soup_status_get_phrase (expected_status));
-               errors++;
-       }
-
-       if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code) &&
-           !soup_message_is_keepalive (msg)) {
-               debug_printf (1, "      ERROR: message is not keepalive!\n");
-               errors++;
-       }
-
-       if (!finished) {
-               debug_printf (1, "      ERROR: 'finished' was not emitted\n");
-               errors++;
-       }
+       soup_test_assert_message_status (msg, expected_status);
+       if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
+               g_assert_true (soup_message_is_keepalive (msg));
+       g_assert_true (finished);
 
        g_signal_handlers_disconnect_by_func (msg,
                                              G_CALLBACK (message_finished),
@@ -63,7 +51,8 @@ static void
 do_msg_tests_for_session (SoupSession *timeout_session,
                          SoupSession *idle_session,
                          SoupSession *plain_session,
-                         char *fast_uri, char *slow_uri)
+                         const char *fast_uri,
+                         const char *slow_uri)
 {
        SoupSocket *ret, *idle_first, *idle_second;
        SoupSocket *plain_first, *plain_second;
@@ -92,10 +81,8 @@ do_msg_tests_for_session (SoupSession *timeout_session,
                                                      (gpointer)request_started_cb,
                                                      &ret);
 
-               if (idle_first == idle_second) {
-                       debug_printf (1, "      ERROR: idle_session did not close first connection\n");
-                       errors++;
-               }
+               soup_test_assert (idle_first != idle_second,
+                                 "idle_session did not close first connection");
                g_object_unref (idle_first);
        }
 
@@ -106,10 +93,8 @@ do_msg_tests_for_session (SoupSession *timeout_session,
                                                      (gpointer)request_started_cb,
                                                      &ret);
 
-               if (plain_first != plain_second) {
-                       debug_printf (1, "      ERROR: plain_session closed connection\n");
-                       errors++;
-               }
+               soup_test_assert (plain_first == plain_second,
+                                 "plain_session closed connection");
                g_object_unref (plain_first);
        }
 }
@@ -132,51 +117,26 @@ do_request_to_session (SoupSession *session, const char *uri,
                          G_CALLBACK (message_finished), &finished);
        stream = soup_test_request_send (req, NULL, 0, &error);
 
-       if (expect_timeout && !error) {
-               debug_printf (1, "      FAILED: request did not time out\n");
-               errors++;
-       } else if (expect_timeout && !g_error_matches (error, G_IO_ERROR,
-                                                      G_IO_ERROR_TIMED_OUT)) {
-               debug_printf (1, "      FAILED: wrong error: %s\n",
-                             error->message);
-               errors++;
-       } else if (!expect_timeout && error) {
-               debug_printf (1, "      FAILED: expected success but got error: %s\n",
-                             error->message);
-               errors++;
-       }
+       if (expect_timeout)
+               g_assert_error (error, G_IO_ERROR, G_IO_ERROR_TIMED_OUT);
+       else
+               g_assert_no_error (error);
        g_clear_error (&error);
 
        if (stream) {
                soup_test_request_read_all (req, stream, NULL, &error);
-               if (error) {
-                       debug_printf (1, "      ERROR reading stream: %s\n",
-                                     error->message);
-                       errors++;
-               }
+               g_assert_no_error (error);
        }
 
        if (stream) {
                soup_test_request_close_stream (req, stream, NULL, &error);
-
-               if (error) {
-                       debug_printf (1, "      ERROR closing stream: %s\n",
-                                     error->message);
-                       errors++;
-               }
+               g_assert_no_error (error);
                g_object_unref (stream);
        }
 
-       if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code) &&
-           !soup_message_is_keepalive (msg)) {
-               debug_printf (1, "      ERROR: message is not keepalive!\n");
-               errors++;
-       }
-
-       if (!finished) {
-               debug_printf (1, "      ERROR: 'finished' was not emitted\n");
-               errors++;
-       }
+       if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
+               g_assert_true (soup_message_is_keepalive (msg));
+       g_assert_true (finished);
 
        g_signal_handlers_disconnect_by_func (msg,
                                              G_CALLBACK (message_finished),
@@ -189,7 +149,8 @@ static void
 do_req_tests_for_session (SoupSession *timeout_session,
                          SoupSession *idle_session,
                          SoupSession *plain_session,
-                         char *fast_uri, char *slow_uri)
+                         const char *fast_uri,
+                         const char *slow_uri)
 {
        SoupSocket *ret, *idle_first, *idle_second;
        SoupSocket *plain_first, *plain_second;
@@ -220,10 +181,8 @@ do_req_tests_for_session (SoupSession *timeout_session,
                                                      (gpointer)request_started_cb,
                                                      &ret);
 
-               if (idle_first == idle_second) {
-                       debug_printf (1, "      ERROR: idle_session did not close first connection\n");
-                       errors++;
-               }
+               soup_test_assert (idle_first != idle_second,
+                                 "idle_session did not close first connection");
                g_object_unref (idle_first);
        }
 
@@ -234,20 +193,30 @@ do_req_tests_for_session (SoupSession *timeout_session,
                                                      (gpointer)request_started_cb,
                                                      &ret);
 
-               if (plain_first != plain_second) {
-                       debug_printf (1, "      ERROR: plain_session closed connection\n");
-                       errors++;
-               }
+               soup_test_assert (plain_first == plain_second,
+                                 "plain_session closed connection");
                g_object_unref (plain_first);
        }
 }
 
 static void
-do_timeout_tests (char *fast_uri, char *slow_uri, gboolean extra_slow)
+do_async_timeout_tests (gconstpointer data)
 {
        SoupSession *timeout_session, *idle_session, *plain_session;
+       const char *fast_uri = data;
+       const char *slow_uri = g_build_path ("/", fast_uri, "slow", NULL);
+       gboolean extra_slow;
+
+       if (g_str_has_prefix (fast_uri, "https")) {
+               if (!tls_available) {
+                       g_test_skip ("TLS not available");
+                       return;
+               }
+
+               extra_slow = slow_https;
+       } else
+               extra_slow = FALSE;
 
-       debug_printf (1, "  async\n");
        timeout_session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC,
                                                 SOUP_SESSION_TIMEOUT, extra_slow ? 3 : 1,
                                                 SOUP_SESSION_USE_THREAD_CONTEXT, TRUE,
@@ -272,8 +241,26 @@ do_timeout_tests (char *fast_uri, char *slow_uri, gboolean extra_slow)
        soup_test_session_abort_unref (timeout_session);
        soup_test_session_abort_unref (idle_session);
        soup_test_session_abort_unref (plain_session);
+}
+
+static void
+do_sync_timeout_tests (gconstpointer data)
+{
+       SoupSession *timeout_session, *plain_session;
+       const char *fast_uri = data;
+       const char *slow_uri = g_build_path ("/", fast_uri, "slow", NULL);
+       gboolean extra_slow;
+
+       if (g_str_has_prefix (fast_uri, "https")) {
+               if (!tls_available) {
+                       g_test_skip ("TLS not available");
+                       return;
+               }
+
+               extra_slow = slow_https;
+       } else
+               extra_slow = FALSE;
 
-       debug_printf (1, "\n  sync\n");
        timeout_session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC,
                                                 SOUP_SESSION_TIMEOUT, extra_slow ? 3 : 1,
                                                 NULL);
@@ -319,57 +306,55 @@ server_handler (SoupServer        *server,
 int
 main (int argc, char **argv)
 {
-       SoupServer *server;
-       char *fast_uri, *slow_uri;
+       SoupServer *server, *https_server = NULL;
+       char *uri, *https_uri = NULL;
+       int ret;
 
        test_init (argc, argv, NULL);
 
-       debug_printf (1, "http\n");
        server = soup_test_server_new (TRUE);
        soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
-       fast_uri = g_strdup_printf ("http://127.0.0.1:%u/";,
-                                   soup_server_get_port (server));
-       slow_uri = g_strdup_printf ("http://127.0.0.1:%u/slow";,
-                                   soup_server_get_port (server));
-       do_timeout_tests (fast_uri, slow_uri, FALSE);
-       g_free (fast_uri);
-       g_free (slow_uri);
-       soup_test_server_quit_unref (server);
+       uri = g_strdup_printf ("http://127.0.0.1:%u/";,
+                              soup_server_get_port (server));
 
        if (tls_available) {
                SoupSession *test_session;
-               gboolean extra_slow;
                gint64 start, end;
 
-               debug_printf (1, "\nhttps\n");
-               server = soup_test_server_new_ssl (TRUE);
-               soup_server_add_handler (server, NULL, server_handler, NULL, NULL);
-               fast_uri = g_strdup_printf ("https://127.0.0.1:%u/";,
-                                           soup_server_get_port (server));
-               slow_uri = g_strdup_printf ("https://127.0.0.1:%u/slow";,
-                                           soup_server_get_port (server));
+               https_server = soup_test_server_new_ssl (TRUE);
+               soup_server_add_handler (https_server, NULL, server_handler, NULL, NULL);
+               https_uri = g_strdup_printf ("https://127.0.0.1:%u/";,
+                                            soup_server_get_port (https_server));
 
                /* The 1-second timeouts are too fast for some machines... */
                test_session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
                start = g_get_monotonic_time ();
-               do_message_to_session (test_session, fast_uri, NULL, SOUP_STATUS_OK);
+               do_message_to_session (test_session, uri, NULL, SOUP_STATUS_OK);
                end = g_get_monotonic_time ();
                soup_test_session_abort_unref (test_session);
                debug_printf (2, "  (https request took %0.3fs)\n", (end - start) / 1000000.0);
                if (end - start > 750000) {
                        debug_printf (1, "  (using extra-slow mode)\n\n");
-                       extra_slow = TRUE;
+                       slow_https = TRUE;
                } else {
                        debug_printf (2, "\n");
-                       extra_slow = FALSE;
+                       slow_https = FALSE;
                }
-
-               do_timeout_tests (fast_uri, slow_uri, extra_slow);
-               g_free (fast_uri);
-               g_free (slow_uri);
-               soup_test_server_quit_unref (server);
        }
 
+       g_test_add_data_func ("/timeout/http/async", uri, do_async_timeout_tests);
+       g_test_add_data_func ("/timeout/http/sync", uri, do_sync_timeout_tests);
+       g_test_add_data_func ("/timeout/https/async", https_uri, do_async_timeout_tests);
+       g_test_add_data_func ("/timeout/https/sync", https_uri, do_sync_timeout_tests);
+
+       ret = g_test_run ();
+
+       g_free (uri);
+       g_free (https_uri);
+       soup_test_server_quit_unref (server);
+       if (https_server)
+               soup_test_server_quit_unref (https_server);
+
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/tld-test.c b/tests/tld-test.c
index d1f1de1..2e7f8a2 100644
--- a/tests/tld-test.c
+++ b/tests/tld-test.c
@@ -7,176 +7,183 @@
 
 /* From http://publicsuffix.org/list/test.txt */
 static struct {
-  const char *hostname;
-  const char *result;
+       const char *hostname;
+       const char *result;
+       SoupTLDError error;
 } tld_tests[] = {
-  /* NULL input. Not checked here because the API requires a valid hostname. */
-  /* { NULL, NULL }, */
-  /* Mixed case. Not checked because the API requires a valid hostname. */
-  /* { "COM", NULL }, */
-  /* { "example.COM", "example.com" }, */
-  /* { "WwW.example.COM", "example.com" }, */
-  /* Leading dot. */
-  { ".com", NULL },
-  { ".example", NULL },
-  { ".example.com", NULL },
-  { ".example.example", NULL },
-  /* TLD with only 1 rule. */
-  { "biz", NULL },
-  { "domain.biz", "domain.biz" },
-  { "b.domain.biz", "domain.biz" },
-  { "a.b.domain.biz", "domain.biz" },
-  /* TLD with some 2-level rules. */
-  { "com", NULL },
-  { "example.com", "example.com" },
-  { "b.example.com", "example.com" },
-  { "a.b.example.com", "example.com" },
-  { "uk.com", NULL },
-  { "example.uk.com", "example.uk.com" },
-  { "b.example.uk.com", "example.uk.com" },
-  { "a.b.example.uk.com", "example.uk.com" },
-  { "test.ac", "test.ac" },
-  /* TLD with only 1 (wildcard) rule. */
-  { "cy", NULL },
-  { "c.cy", NULL },
-  { "b.c.cy", "b.c.cy" },
-  { "a.b.c.cy", "b.c.cy" },
-  /* More complex TLD. */
-  { "jp", NULL },
-  { "test.jp", "test.jp" },
-  { "www.test.jp", "test.jp" },
-  { "ac.jp", NULL },
-  { "test.ac.jp", "test.ac.jp" },
-  { "www.test.ac.jp", "test.ac.jp" },
-  { "kyoto.jp", NULL },
-  { "minami.kyoto.jp", NULL },
-  { "b.minami.kyoto.jp", "b.minami.kyoto.jp" },
-  { "a.b.minami.kyoto.jp", "b.minami.kyoto.jp" },
-  { "pref.kyoto.jp", "pref.kyoto.jp" },
-  { "www.pref.kyoto.jp", "pref.kyoto.jp" },
-  { "city.kyoto.jp", "city.kyoto.jp" },
-  { "www.city.kyoto.jp", "city.kyoto.jp" },
-  /* TLD with a wildcard rule and exceptions. */
-  { "ck", NULL },
-  { "test.ck", NULL },
-  { "b.test.ck", "b.test.ck" },
-  { "a.b.test.ck", "b.test.ck" },
-  { "www.ck", "www.ck" },
-  { "www.www.ck", "www.ck" },
-  /* US K12. */
-  { "us", NULL },
-  { "test.us", "test.us" },
-  { "www.test.us", "test.us" },
-  { "ak.us", NULL },
-  { "test.ak.us", "test.ak.us" },
-  { "www.test.ak.us", "test.ak.us" },
-  { "k12.ak.us", NULL },
-  { "test.k12.ak.us", "test.k12.ak.us" },
-  { "www.test.k12.ak.us", "test.k12.ak.us" },
-  /* IDN labels. */
-  { "食狮.com.cn", "食狮.com.cn" },
-  { "食狮.公司.cn", "食狮.公司.cn" },
-  { "www.食狮.公司.cn", "食狮.公司.cn" },
-  { "shishi.公司.cn", "shishi.公司.cn" },
-  { "公司.cn", NULL },
-  { "食狮.中国", "食狮.中国" },
-  { "www.食狮.中国", "食狮.中国" },
-  { "shishi.中国", "shishi.中国" },
-  { "中国", NULL },
-  /* Same as above, but punycoded. */
-  { "xn--85x722f.com.cn", "xn--85x722f.com.cn" },
-  { "xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn" },
-  { "www.xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn" },
-  { "shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn" },
-  { "xn--55qx5d.cn", NULL },
-  { "xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s" },
-  { "www.xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s" },
-  { "shishi.xn--fiqs8s", "shishi.xn--fiqs8s" },
-  { "xn--fiqs8s", NULL },
-  /* End of publicsuffix.org tests */
-
-  /* Let's just double-check this one... */
-  { "co.uk", NULL },
-  { "test.co.uk", "test.co.uk" },
-  { "www.test.co.uk", "test.co.uk" },
-
-  /* Two levels of non-ASCII */
-  { "våler.østfold.no", NULL },
-  { "test.våler.østfold.no", "test.våler.østfold.no" },
-  { "www.test.våler.østfold.no", "test.våler.østfold.no" },
-  { "xn--vler-qoa.xn--stfold-9xa.no", NULL },
-  { "test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no" },
-  { "www.test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no" },
+       /* NULL input. Not checked here because the API requires a valid hostname. */
+       /* { NULL, NULL, -1 }, */
+       /* Mixed case. Not checked because the API requires a valid hostname. */
+       /* { "COM", NULL, -1 }, */
+       /* { "example.COM", "example.com", -1 }, */
+       /* { "WwW.example.COM", "example.com", -1 }, */
+       /* Leading dot. */
+       { ".com", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
+       { ".example", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
+       { ".example.com", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
+       { ".example.example", NULL, SOUP_TLD_ERROR_INVALID_HOSTNAME },
+       /* TLD with only 1 rule. */
+       { "biz", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "domain.biz", "domain.biz", -1 },
+       { "b.domain.biz", "domain.biz", -1 },
+       { "a.b.domain.biz", "domain.biz", -1 },
+       /* TLD with some 2-level rules. */
+       { "com", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "example.com", "example.com", -1 },
+       { "b.example.com", "example.com", -1 },
+       { "a.b.example.com", "example.com", -1 },
+       { "uk.com", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "example.uk.com", "example.uk.com", -1 },
+       { "b.example.uk.com", "example.uk.com", -1 },
+       { "a.b.example.uk.com", "example.uk.com", -1 },
+       { "test.ac", "test.ac", -1 },
+       /* TLD with only 1 (wildcard) rule. */
+       { "cy", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "c.cy", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "b.c.cy", "b.c.cy", -1 },
+       { "a.b.c.cy", "b.c.cy", -1 },
+       /* More complex TLD. */
+       { "jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.jp", "test.jp", -1 },
+       { "www.test.jp", "test.jp", -1 },
+       { "ac.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.ac.jp", "test.ac.jp", -1 },
+       { "www.test.ac.jp", "test.ac.jp", -1 },
+       { "kyoto.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "minami.kyoto.jp", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "b.minami.kyoto.jp", "b.minami.kyoto.jp", -1 },
+       { "a.b.minami.kyoto.jp", "b.minami.kyoto.jp", -1 },
+       { "pref.kyoto.jp", "pref.kyoto.jp", -1 },
+       { "www.pref.kyoto.jp", "pref.kyoto.jp", -1 },
+       { "city.kyoto.jp", "city.kyoto.jp", -1 },
+       { "www.city.kyoto.jp", "city.kyoto.jp", -1 },
+       /* TLD with a wildcard rule and exceptions. */
+       { "ck", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.ck", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "b.test.ck", "b.test.ck", -1 },
+       { "a.b.test.ck", "b.test.ck", -1 },
+       { "www.ck", "www.ck", -1 },
+       { "www.www.ck", "www.ck", -1 },
+       /* US K12. */
+       { "us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.us", "test.us", -1 },
+       { "www.test.us", "test.us", -1 },
+       { "ak.us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.ak.us", "test.ak.us", -1 },
+       { "www.test.ak.us", "test.ak.us", -1 },
+       { "k12.ak.us", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.k12.ak.us", "test.k12.ak.us", -1 },
+       { "www.test.k12.ak.us", "test.k12.ak.us", -1 },
+       /* IDN labels. */
+       { "食狮.com.cn", "食狮.com.cn", -1 },
+       { "食狮.公司.cn", "食狮.公司.cn", -1 },
+       { "www.食狮.公司.cn", "食狮.公司.cn", -1 },
+       { "shishi.公司.cn", "shishi.公司.cn", -1 },
+       { "公司.cn", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "食狮.中国", "食狮.中国", -1 },
+       { "www.食狮.中国", "食狮.中国", -1 },
+       { "shishi.中国", "shishi.中国", -1 },
+       { "中国", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       /* Same as above, but punycoded. */
+       { "xn--85x722f.com.cn", "xn--85x722f.com.cn", -1 },
+       { "xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn", -1 },
+       { "www.xn--85x722f.xn--55qx5d.cn", "xn--85x722f.xn--55qx5d.cn", -1 },
+       { "shishi.xn--55qx5d.cn", "shishi.xn--55qx5d.cn", -1 },
+       { "xn--55qx5d.cn", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s", -1 },
+       { "www.xn--85x722f.xn--fiqs8s", "xn--85x722f.xn--fiqs8s", -1 },
+       { "shishi.xn--fiqs8s", "shishi.xn--fiqs8s", -1 },
+       { "xn--fiqs8s", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       /* End of publicsuffix.org tests */
+
+       /* Let's just double-check this one... */
+       { "co.uk", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.co.uk", "test.co.uk", -1 },
+       { "www.test.co.uk", "test.co.uk", -1 },
+
+       /* Two levels of non-ASCII */
+       { "våler.østfold.no", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.våler.østfold.no", "test.våler.østfold.no", -1 },
+       { "www.test.våler.østfold.no", "test.våler.østfold.no", -1 },
+       { "xn--vler-qoa.xn--stfold-9xa.no", NULL, SOUP_TLD_ERROR_NOT_ENOUGH_DOMAINS },
+       { "test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no", -1 },
+       { "www.test.xn--vler-qoa.xn--stfold-9xa.no", "test.xn--vler-qoa.xn--stfold-9xa.no", -1 },
 },
+
 /* Non Internet TLDs have NULL as expected result
  */
 non_inet_tld_tests[] = {
-  /* Unlisted TLD.*/
-  { "example", NULL },
-  { "example.example", NULL },
-  { "b.example.example", NULL },
-  { "a.b.example.example", NULL },
-  /* Listed, but non-Internet, TLD. */
-  { "local", NULL },
-  { "example.local", NULL },
-  { "b.example.local", NULL },
-  { "a.b.example.local", NULL }
+       /* Unlisted TLD.*/
+       { "example", NULL },
+       { "example.example", NULL },
+       { "b.example.example", NULL },
+       { "a.b.example.example", NULL },
+       /* Listed, but non-Internet, TLD. */
+       { "local", NULL },
+       { "example.local", NULL },
+       { "b.example.local", NULL },
+       { "a.b.example.local", NULL }
 };
 
-int
-main (int argc, char **argv)
+static void
+do_inet_tests (void)
 {
        int i;
 
-       test_init (argc, argv, NULL);
-
-       errors = 0;
-       for (i = 0; i < G_N_ELEMENTS (tld_tests); ++i) {
+       for (i = 0; i < G_N_ELEMENTS (tld_tests); i++) {
                GError *error = NULL;
-               gboolean is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
-               const char *base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, &error);
-
-               debug_printf (1, "Testing %s: ", tld_tests[i].hostname);
-
-               if (is_public && tld_tests[i].result) {
-                       debug_printf (1, "ERROR: domain is public but base_domain is not NULL (%s)\n",
-                                     base_domain);
-                       ++errors;
-               } else if (g_strcmp0 (tld_tests[i].result, base_domain)) {
-                       debug_printf (1, "ERROR: %s expected as base domain but got %s\n",
-                                     tld_tests[i].result, base_domain);
-                       ++errors;
-
-               } else if (!tld_tests[i].result && !is_public &&
-                          !g_error_matches (error, SOUP_TLD_ERROR, SOUP_TLD_ERROR_INVALID_HOSTNAME)) {
-                       debug_printf (1, "ERROR: not public domain with NULL expected result\n");
-                       ++errors;
-               } else
-                       debug_printf (1, "OK\n");
-
-               g_clear_error(&error);
+               gboolean is_public;
+               const char *base_domain;
+
+               debug_printf (1, "Testing %s\n", tld_tests[i].hostname);
+
+               is_public = soup_tld_domain_is_public_suffix (tld_tests[i].hostname);
+               base_domain = soup_tld_get_base_domain (tld_tests[i].hostname, &error);
+
+               if (base_domain) {
+                       g_assert_no_error (error);
+                       g_assert_false (is_public);
+                       g_assert_cmpstr (base_domain, ==, tld_tests[i].result);
+               } else {
+                       g_assert_null (tld_tests[i].result);
+                       g_assert_error (error, SOUP_TLD_ERROR, tld_tests[i].error);
+                       g_clear_error (&error);
+               }
        }
+}
+
+static void
+do_non_inet_tests (void)
+{
+       int i;
 
-       debug_printf (1, "\n");
+       for (i = 0; i < G_N_ELEMENTS (non_inet_tld_tests); i++) {
+               gboolean is_public;
+               const char *base_domain;
 
-       for (i = 0; i < G_N_ELEMENTS (non_inet_tld_tests); ++i) {
-               gboolean is_public = soup_tld_domain_is_public_suffix (non_inet_tld_tests[i].hostname);
-               const char *base_domain = soup_tld_get_base_domain (non_inet_tld_tests[i].hostname, NULL);
+               debug_printf (1, "Testing %s\n", non_inet_tld_tests[i].hostname);
 
-               debug_printf (1, "Testing %s: ", non_inet_tld_tests[i].hostname);
+               is_public = soup_tld_domain_is_public_suffix (non_inet_tld_tests[i].hostname);
+               base_domain = soup_tld_get_base_domain (non_inet_tld_tests[i].hostname, NULL);
 
-               if (is_public) {
-                       debug_printf (1, "ERROR: domain incorrectly clasified as public\n");
-                       ++errors;
-               } else if (base_domain) {
-                       debug_printf (1, "ERROR: non NULL base domain (%s) for local url\n",
-                                     base_domain);
-                       ++errors;
-               } else
-                       debug_printf (1, "OK\n");
+               g_assert_false (is_public);
+               g_assert_null (base_domain);
        }
+}
+
+int
+main (int argc, char **argv)
+{
+       int ret;
+
+       test_init (argc, argv, NULL);
+
+       g_test_add_func ("/tld/inet", do_inet_tests);
+       g_test_add_func ("/tld/non-inet", do_non_inet_tests);
+
+       ret = g_test_run ();
 
        test_cleanup ();
 
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/uri-parsing.c b/tests/uri-parsing.c
index b4f495b..e67253e 100644
--- a/tests/uri-parsing.c
+++ b/tests/uri-parsing.c
@@ -266,39 +266,7 @@ static struct {
 };
 static int num_eq_tests = G_N_ELEMENTS(eq_tests);
 
-#define test_cmpstr(a, b) _test_cmpstr (#a, #b, a, b)
-
-static gboolean
-_test_cmpstr (const char *got_desc,
-             const char *exp_desc,
-             const char *got,
-             const char *expected)
-{
-       if (got == expected)
-               return TRUE;
-
-       if (got == NULL) {
-               debug_printf (1, "ERR\n  %s = NULL, expected %s = \"%s\"\n",
-                             got_desc, exp_desc, expected);
-               return FALSE;
-       }
-
-       if (expected == NULL) {
-               debug_printf (1, "ERR\n  %s = \"%s\", expected %s = NULL\n",
-                             got_desc, got, exp_desc);
-               return FALSE;
-       }
-
-       if (strcmp (got, expected) != 0) {
-               debug_printf (1, "ERR\n  %s = \"%s\", expected %s = \"%s\"\n",
-                             got_desc, got, exp_desc, expected);
-               return FALSE;
-       }
-
-       return TRUE;
-}
-
-static gboolean
+static void
 do_uri (SoupURI *base_uri, const char *base_str,
        const char *in_uri, const char *out_uri,
        const SoupURI *bits)
@@ -307,76 +275,89 @@ do_uri (SoupURI *base_uri, const char *base_str,
        char *uri_string;
 
        if (base_uri) {
-               debug_printf (1, "<%s> + <%s> = <%s>? ", base_str, in_uri,
+               debug_printf (1, "<%s> + <%s> = <%s>\n", base_str, in_uri,
                              out_uri ? out_uri : "ERR");
                uri = soup_uri_new_with_base (base_uri, in_uri);
        } else {
-               debug_printf (1, "<%s> => <%s>? ", in_uri,
+               debug_printf (1, "<%s> => <%s>\n", in_uri,
                              out_uri ? out_uri : "ERR");
                uri = soup_uri_new (in_uri);
        }
 
        if (!uri) {
-               if (out_uri) {
-                       debug_printf (1, "ERR\n  Could not parse %s\n", in_uri);
-                       return FALSE;
-               } else {
-                       debug_printf (1, "OK\n");
-                       return TRUE;
-               }
+               g_assert_null (out_uri);
+               return;
        }
 
        if (bits != NULL) {
-               gboolean failed = FALSE;
-
-               if (!test_cmpstr (uri->scheme, bits->scheme))
-                       failed = TRUE;
+               g_assert_cmpstr (uri->scheme, ==, bits->scheme);
+               g_assert_cmpstr (uri->user, ==, bits->user);
+               g_assert_cmpstr (uri->password, ==, bits->password);
+               g_assert_cmpstr (uri->host, ==, bits->host);
+               g_assert_cmpuint (uri->port, ==, bits->port);
+               g_assert_cmpstr (uri->path, ==, bits->path);
+               g_assert_cmpstr (uri->query, ==, bits->query);
+               g_assert_cmpstr (uri->fragment, ==, bits->fragment);
+       }
 
-               if (!test_cmpstr (uri->user, bits->user))
-                       failed = TRUE;
+       uri_string = soup_uri_to_string (uri, FALSE);
+       soup_uri_free (uri);
 
-               if (!test_cmpstr (uri->password, bits->password))
-                       failed = TRUE;
+       g_assert_cmpstr (uri_string, ==, out_uri);
+       g_free (uri_string);
+}
 
-               if (!test_cmpstr (uri->host, bits->host))
-                       failed = TRUE;
+static void
+do_absolute_uri_tests (void)
+{
+       int i;
 
-               if (uri->port != bits->port) {
-                       debug_printf (1, "ERR\n  port was %u, expected %u\n",
-                                     uri->port, bits->port);
-                       failed = TRUE;
-               }
+       for (i = 0; i < num_abs_tests; i++) {
+               do_uri (NULL, NULL, abs_tests[i].uri_string,
+                       abs_tests[i].result, &abs_tests[i].bits);
+       }
+}
 
-               if (!test_cmpstr (uri->path, bits->path))
-                       failed = TRUE;
+static void
+do_relative_uri_tests (void)
+{
+       SoupURI *base_uri;
+       char *uri_string;
+       int i;
 
-               if (!test_cmpstr (uri->query, bits->query))
-                       failed = TRUE;
+       base_uri = soup_uri_new (base);
+       if (!base_uri) {
+               g_printerr ("Could not parse %s!\n", base);
+               exit (1);
+       }
 
-               if (!test_cmpstr (uri->fragment, bits->fragment))
-                       failed = TRUE;
+       uri_string = soup_uri_to_string (base_uri, FALSE);
+       g_assert_cmpstr (uri_string, ==, base);
+       g_free (uri_string);
 
-               if (failed)
-                       return FALSE;
+       for (i = 0; i < num_rel_tests; i++) {
+               do_uri (base_uri, base, rel_tests[i].uri_string,
+                       rel_tests[i].result, &rel_tests[i].bits);
        }
+       soup_uri_free (base_uri);
+}
 
-       uri_string = soup_uri_to_string (uri, FALSE);
-       soup_uri_free (uri);
+static void
+do_equality_tests (void)
+{
+       SoupURI *uri1, *uri2;
+       int i;
 
-       if (!out_uri) {
-               debug_printf (1, "ERR\n  Got %s\n", uri_string);
-               return FALSE;
-       }
+       for (i = 0; i < num_eq_tests; i++) {
+               uri1 = soup_uri_new (eq_tests[i].one);
+               uri2 = soup_uri_new (eq_tests[i].two);
 
-       if (strcmp (uri_string, out_uri) != 0) {
-               debug_printf (1, "NO\n  Unparses to <%s>\n", uri_string);
-               g_free (uri_string);
-               return FALSE;
-       }
-       g_free (uri_string);
+               debug_printf (1, "<%s> == <%s>\n", eq_tests[i].one, eq_tests[i].two);
+               g_assert_true (soup_uri_equal (uri1, uri2));
 
-       debug_printf (1, "OK\n");
-       return TRUE;
+               soup_uri_free (uri1);
+               soup_uri_free (uri2);
+       }
 }
 
 static void
@@ -385,146 +366,80 @@ do_soup_uri_null_tests (void)
        SoupURI *uri, *uri2;
        char *uri_string;
 
-       debug_printf (1, "\nsoup_uri_new (NULL)\n");
        uri = soup_uri_new (NULL);
-       if (SOUP_URI_IS_VALID (uri) || SOUP_URI_VALID_FOR_HTTP (uri)) {
-               debug_printf (1, "  ERROR: soup_uri_new(NULL) returns valid URI?\n");
-               errors++;
-       }
+       g_assert_false (SOUP_URI_IS_VALID (uri));
+       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
 
        /* This implicitly also verifies that none of these methods g_warn */
-       if (soup_uri_get_scheme (uri) ||
-           soup_uri_get_user (uri) ||
-           soup_uri_get_password (uri) ||
-           soup_uri_get_host (uri) ||
-           soup_uri_get_port (uri) ||
-           soup_uri_get_path (uri) ||
-           soup_uri_get_query (uri) ||
-           soup_uri_get_fragment (uri)) {
-               debug_printf (1, "  ERROR: soup_uri_new(NULL) returns non-empty URI?\n");
-               errors++;
-       }
-
-       expect_warning = TRUE;
+       g_assert_null (soup_uri_get_scheme (uri));
+       g_assert_null (soup_uri_get_user (uri));
+       g_assert_null (soup_uri_get_password (uri));
+       g_assert_null (soup_uri_get_host (uri));
+       g_assert_cmpint (soup_uri_get_port (uri), ==, 0);
+       g_assert_null (soup_uri_get_path (uri));
+       g_assert_null (soup_uri_get_query (uri));
+       g_assert_null (soup_uri_get_fragment (uri));
+
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_CRITICAL,
+                              "*base == NULL*");
        uri2 = soup_uri_new_with_base (uri, "/path");
-       if (uri2 || expect_warning) {
-               debug_printf (1, "  ERROR: soup_uri_new_with_base didn't fail on NULL URI?\n");
-               errors++;
-               expect_warning = FALSE;
-       }
+       g_test_assert_expected_messages ();
+       g_assert_null (uri2);
 
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*SOUP_URI_IS_VALID*");
        uri_string = soup_uri_to_string (uri, FALSE);
-       if (expect_warning) {
-               debug_printf (1, "  ERROR: soup_uri_to_string didn't fail on NULL URI?\n");
-               errors++;
-               expect_warning = FALSE;
-       } else if (*uri_string) {
-               debug_printf (1, "  ERROR: soup_uri_to_string on NULL URI returned '%s'\n",
-                             uri_string);
-               errors++;
-       }
+       g_test_assert_expected_messages ();
+       g_assert_cmpstr (uri_string, ==, "");
        g_free (uri_string);
 
        soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);
-       if (SOUP_URI_IS_VALID (uri) || SOUP_URI_VALID_FOR_HTTP (uri)) {
-               debug_printf (1, "  ERROR: setting scheme on NULL URI makes it valid?\n");
-               errors++;
-       }
+       g_assert_false (SOUP_URI_IS_VALID (uri));
+       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
 
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*SOUP_URI_IS_VALID*");
        uri_string = soup_uri_to_string (uri, FALSE);
-       if (expect_warning) {
-               debug_printf (1, "  ERROR: soup_uri_to_string didn't fail on scheme-only URI?\n");
-               errors++;
-               expect_warning = FALSE;
-       } else if (strcmp (uri_string, "http:") != 0) {
-               debug_printf (1, "  ERROR: soup_uri_to_string returned '%s' instead of 'http:'\n",
-                             uri_string);
-               errors++;
-       }
+       g_test_assert_expected_messages ();
+       g_assert_cmpstr (uri_string, ==, "http:");
        g_free (uri_string);
 
        soup_uri_set_host (uri, "localhost");
-       if (SOUP_URI_IS_VALID (uri)) {
-               debug_printf (1, "  ERROR: setting scheme+host on NULL URI makes it valid?\n");
-               errors++;
-       }
-       if (SOUP_URI_VALID_FOR_HTTP (uri)) {
-               debug_printf (1, "  ERROR: setting scheme+host on NULL URI makes it valid for http?\n");
-               errors++;
-       }
+       g_assert_false (SOUP_URI_IS_VALID (uri));
+       g_assert_false (SOUP_URI_VALID_FOR_HTTP (uri));
 
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*SOUP_URI_IS_VALID*");
        uri_string = soup_uri_to_string (uri, FALSE);
-       if (expect_warning) {
-               debug_printf (1, "  ERROR: soup_uri_to_string didn't fail on scheme+host URI?\n");
-               errors++;
-               expect_warning = FALSE;
-       } else if (strcmp (uri_string, "http://localhost/";) != 0) {
-               debug_printf (1, "  ERROR: soup_uri_to_string with NULL path returned '%s' instead of 
'http://localhost/'\n",
-                             uri_string);
-               errors++;
-       }
+       g_test_assert_expected_messages ();
+       g_assert_cmpstr (uri_string, ==, "http://localhost/";);
        g_free (uri_string);
 
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*SOUP_URI_IS_VALID*");
        uri2 = soup_uri_new_with_base (uri, "/path");
-       if (expect_warning) {
-               debug_printf (1, "  ERROR: soup_uri_new_with_base didn't warn on NULL+scheme URI?\n");
-               errors++;
-               expect_warning = FALSE;
-       } else if (!uri2) {
-               debug_printf (1, "  ERROR: soup_uri_new_with_base didn't fix path on NULL+scheme URI\n");
-               errors++;
-       }
+       g_test_assert_expected_messages ();
+       g_assert_true (uri2 != NULL);
 
        if (uri2) {
                uri_string = soup_uri_to_string (uri2, FALSE);
-               if (!uri_string) {
-                       debug_printf (1, "  ERROR: soup_uri_to_string failed on uri2?\n");
-                       errors++;
-               } else if (strcmp (uri_string, "http://localhost/path";) != 0) {
-                       debug_printf (1, "  ERROR: soup_uri_to_string returned '%s' instead of 
'http://localhost/path'\n",
-                                     uri_string);
-                       errors++;
-               }
+               g_assert_cmpstr (uri_string, ==, "http://localhost/path";);
                g_free (uri_string);
                soup_uri_free (uri2);
        }
 
-       expect_warning = TRUE;
+       g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
+                              "*path != NULL*");
        soup_uri_set_path (uri, NULL);
-       if (expect_warning) {
-               debug_printf (1, "  ERROR: setting path to NULL doesn't warn\n");
-               errors++;
-               expect_warning = FALSE;
-       }
-       if (!uri->path || *uri->path) {
-               debug_printf (1, "  ERROR: setting path to NULL != \"\"\n");
-               errors++;
-               soup_uri_set_path (uri, "");
-       }
+       g_test_assert_expected_messages ();
+       g_assert_cmpstr (uri->path, ==, "");
 
        uri_string = soup_uri_to_string (uri, FALSE);
-       if (!uri_string) {
-               debug_printf (1, "  ERROR: soup_uri_to_string failed on complete URI?\n");
-               errors++;
-       } else if (strcmp (uri_string, "http://localhost/";) != 0) {
-               debug_printf (1, "  ERROR: soup_uri_to_string with empty path returned '%s' instead of 
'http://localhost/'\n",
-                             uri_string);
-               errors++;
-       }
+       g_assert_cmpstr (uri_string, ==, "http://localhost/";);
        g_free (uri_string);
 
-       if (!SOUP_URI_IS_VALID (uri)) {
-               debug_printf (1, "  ERROR: setting scheme+path on NULL URI doesn't make it valid?\n");
-               errors++;
-       }
-       if (!SOUP_URI_VALID_FOR_HTTP (uri)) {
-               debug_printf (1, "  ERROR: setting scheme+host+path on NULL URI doesn't make it valid for 
http?\n");
-               errors++;
-       }
+       g_assert_true (SOUP_URI_IS_VALID (uri));
+       g_assert_true (SOUP_URI_VALID_FOR_HTTP (uri));
 
        soup_uri_free (uri);
 }
@@ -549,29 +464,21 @@ do_normalization_tests (void)
        char *normalized;
        int i;
 
-       debug_printf (1, "\nsoup_uri_normalize\n");
-
        for (i = 0; i < num_normalization_tests; i++) {
                if (normalization_tests[i].unescape_extra) {
-                       debug_printf (1, "<%s> unescaping <%s> => <%s>: ",
+                       debug_printf (1, "<%s> unescaping <%s> => <%s>\n",
                                      normalization_tests[i].uri_string,
                                      normalization_tests[i].unescape_extra,
                                      normalization_tests[i].result);
                } else {
-                       debug_printf (1, "<%s> => <%s>: ",
+                       debug_printf (1, "<%s> => <%s>\n",
                                      normalization_tests[i].uri_string,
                                      normalization_tests[i].result);
                }
 
                normalized = soup_uri_normalize (normalization_tests[i].uri_string,
                                                 normalization_tests[i].unescape_extra);
-
-               if (!strcmp (normalized, normalization_tests[i].result))
-                       debug_printf (1, "OK\n");
-               else {
-                       debug_printf (1, "NO, got <%s>\n", normalized);
-                       errors++;
-               }
+               g_assert_cmpstr (normalized, ==, normalization_tests[i].result);
                g_free (normalized);
        }
 }
@@ -579,62 +486,18 @@ do_normalization_tests (void)
 int
 main (int argc, char **argv)
 {
-       SoupURI *base_uri, *uri1, *uri2;
-       char *uri_string;
-       int i;
+       int ret;
 
        test_init (argc, argv, NULL);
 
-       debug_printf (1, "Absolute URI parsing\n");
-       for (i = 0; i < num_abs_tests; i++) {
-               if (!do_uri (NULL, NULL, abs_tests[i].uri_string,
-                            abs_tests[i].result, &abs_tests[i].bits))
-                       errors++;
-       }
-
-       debug_printf (1, "\nRelative URI parsing\n");
-       base_uri = soup_uri_new (base);
-       if (!base_uri) {
-               g_printerr ("Could not parse %s!\n", base);
-               exit (1);
-       }
-
-       uri_string = soup_uri_to_string (base_uri, FALSE);
-       if (strcmp (uri_string, base) != 0) {
-               g_printerr ("URI <%s> unparses to <%s>\n",
-                           base, uri_string);
-               errors++;
-       }
-       g_free (uri_string);
-
-       for (i = 0; i < num_rel_tests; i++) {
-               if (!do_uri (base_uri, base, rel_tests[i].uri_string,
-                            rel_tests[i].result, &rel_tests[i].bits))
-                       errors++;
-       }
-       soup_uri_free (base_uri);
-
-       debug_printf (1, "\nURI equality testing\n");
-       for (i = 0; i < num_eq_tests; i++) {
-               uri1 = soup_uri_new (eq_tests[i].one);
-               uri2 = soup_uri_new (eq_tests[i].two);
-               debug_printf (1, "<%s> == <%s>? ", eq_tests[i].one, eq_tests[i].two);
-               if (soup_uri_equal (uri1, uri2))
-                       debug_printf (1, "OK\n");
-               else {
-                       debug_printf (1, "NO\n");
-                       debug_printf (1, "%s : %s : %s\n%s : %s : %s\n",
-                                     uri1->scheme, uri1->host, uri1->path,
-                                     uri2->scheme, uri2->host, uri2->path);
-                       errors++;
-               }
-               soup_uri_free (uri1);
-               soup_uri_free (uri2);
-       }
+       g_test_add_func ("/uri/absolute", do_absolute_uri_tests);
+       g_test_add_func ("/uri/relative", do_relative_uri_tests);
+       g_test_add_func ("/uri/equality", do_equality_tests);
+       g_test_add_func ("/uri/null", do_soup_uri_null_tests);
+       g_test_add_func ("/uri/normalization", do_normalization_tests);
 
-       do_soup_uri_null_tests ();
-       do_normalization_tests ();
+       ret = g_test_run ();
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
diff --git a/tests/xmlrpc-server-test.c b/tests/xmlrpc-server-test.c
index 421348b..a6f2d5f 100644
--- a/tests/xmlrpc-server-test.c
+++ b/tests/xmlrpc-server-test.c
@@ -242,7 +242,7 @@ server_callback (SoupServer *server, SoupMessage *msg,
 static void
 xmlrpc_test_exited (GPid pid, int status, gpointer data)
 {
-       errors = WIFEXITED (status) ? WEXITSTATUS (status) : 1;
+       g_assert_true (WIFEXITED (status) && WEXITSTATUS (status) == 0);
        g_main_loop_quit (loop);
 }
 
@@ -270,9 +270,10 @@ xmlrpc_test_print (GIOChannel *io, GIOCondition cond, gpointer data)
 }
 
 static void
-do_xmlrpc_tests (SoupURI *uri)
+do_xmlrpc_tests (gconstpointer data)
 {
-       char *argv[8];
+       SoupURI *uri = (SoupURI *)data;
+       char *argv[10];
        int arg, out;
        gboolean ok;
        GPid pid;
@@ -280,13 +281,14 @@ do_xmlrpc_tests (SoupURI *uri)
        GIOChannel *child_out;
 
        argv[0] = "./xmlrpc-test";
-       argv[1] = "-s";
-       argv[2] = "-u";
+       argv[1] = "-S";
+       argv[2] = "-U";
        argv[3] = soup_uri_to_string (uri, FALSE);
+       argv[4] = "-q";
 
        for (arg = 0; arg < debug_level && arg < 3; arg++)
-               argv[arg + 4] = "-d";
-       argv[arg + 4] = NULL;
+               argv[arg + 5] = "-d";
+       argv[arg + 5] = NULL;
 
        ok = g_spawn_async_with_pipes (NULL, argv, NULL,
                                       G_SPAWN_DO_NOT_REAP_CHILD,
@@ -295,17 +297,18 @@ do_xmlrpc_tests (SoupURI *uri)
                                       &error);
        g_free (argv[3]);
 
-       if (!ok) {
-               g_print ("Could not run xmlrpc-test: %s\n", error->message);
-               errors++;
+       g_assert_no_error (error);
+       if (!ok)
                return;
-       }
 
        g_child_watch_add (pid, xmlrpc_test_exited, NULL);
        child_out = g_io_channel_unix_new (out);
        g_io_add_watch (child_out, G_IO_IN | G_IO_ERR | G_IO_HUP,
                        xmlrpc_test_print, NULL);
        g_io_channel_unref (child_out);
+
+       g_main_loop_run (loop);
+       g_main_loop_unref (loop);
 }
 
 gboolean run_tests = TRUE;
@@ -322,6 +325,7 @@ main (int argc, char **argv)
 {
        SoupServer *server;
        SoupURI *uri;
+       int ret;
 
        test_init (argc, argv, no_test_entry);
 
@@ -334,18 +338,25 @@ main (int argc, char **argv)
        if (run_tests) {
                uri = soup_uri_new ("http://127.0.0.1/xmlrpc-server.php";);
                soup_uri_set_port (uri, soup_server_get_port (server));
-               do_xmlrpc_tests (uri);
+
+               g_test_add_data_func ("/xmlrpc/server", uri, do_xmlrpc_tests);
+
+               ret = g_test_run ();
+
                soup_uri_free (uri);
-       } else
+       } else {
                g_print ("Listening on port %d\n", soup_server_get_port (server));
 
-       g_main_loop_run (loop);
-       g_main_loop_unref (loop);
+               g_main_loop_run (loop);
+               g_main_loop_unref (loop);
+
+               ret = 0;
+       }
 
        soup_test_server_quit_unref (server);
        if (run_tests)
                test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_PHP_XMLRPC */
diff --git a/tests/xmlrpc-test.c b/tests/xmlrpc-test.c
index 3c3f76f..3a7b20a 100644
--- a/tests/xmlrpc-test.c
+++ b/tests/xmlrpc-test.c
@@ -39,21 +39,16 @@ send_xmlrpc (const char *body, GValue *retval)
                                  body, strlen (body));
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "ERROR: %d %s\n", msg->status_code,
-                             msg->reason_phrase);
-               g_object_unref (msg);
-               return FALSE;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
                                                msg->response_body->length,
                                                retval, &err)) {
                if (err) {
-                       debug_printf (1, "FAULT: %d %s\n", err->code, err->message);
+                       soup_test_assert (FALSE, "FAULT: %d %s\n", err->code, err->message);
                        g_error_free (err);
                } else
-                       debug_printf (1, "ERROR: could not parse response\n");
+                       soup_test_assert (FALSE, "ERROR: could not parse response\n");
                g_object_unref (msg);
                return FALSE;
        }
@@ -92,8 +87,7 @@ check_xmlrpc (GValue *value, GType type, ...)
        va_list args;
 
        if (!G_VALUE_HOLDS (value, type)) {
-               debug_printf (1, "ERROR: could not parse response\n");
-               g_value_unset (value);
+               g_assert_true (G_VALUE_HOLDS (value, type));
                return FALSE;
        }
 
@@ -103,7 +97,7 @@ check_xmlrpc (GValue *value, GType type, ...)
        return TRUE;
 }
 
-static gboolean
+static void
 test_sum (void)
 {
        GValueArray *ints;
@@ -129,14 +123,13 @@ test_sum (void)
        g_value_array_free (ints);
 
        if (!ok)
-               return FALSE;
+               return;
 
-       debug_printf (2, "%d: ", result);
-       debug_printf (1, "%s\n", result == sum ? "OK!" : "WRONG!");
-       return result == sum;
+       debug_printf (2, "%d\n", result);
+       g_assert_cmpint (result, ==, sum);
 }
 
-static gboolean
+static void
 test_countBools (void)
 {
        GValueArray *bools;
@@ -166,25 +159,19 @@ test_countBools (void)
              check_xmlrpc (&retval, G_TYPE_HASH_TABLE, &result));
        g_value_array_free (bools);
        if (!ok)
-               return FALSE;
+               return;
+
+       g_assert_true (soup_value_hash_lookup (result, "true", G_TYPE_INT, &ret_trues));
+       g_assert_true (soup_value_hash_lookup (result, "false", G_TYPE_INT, &ret_falses));
 
-       if (!soup_value_hash_lookup (result, "true", G_TYPE_INT, &ret_trues)) {
-               debug_printf (1, "NO 'true' value in response\n");
-               return FALSE;
-       }
-       if (!soup_value_hash_lookup (result, "false", G_TYPE_INT, &ret_falses)) {
-               debug_printf (1, "NO 'false' value in response\n");
-               return FALSE;
-       }
        g_hash_table_destroy (result);
 
-       debug_printf (2, "{ true: %d, false: %d } ", ret_trues, ret_falses);
-       ok = (trues == ret_trues) && (falses == ret_falses);
-       debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!");
-       return ok;
+       debug_printf (2, "{ true: %d, false: %d }\n", ret_trues, ret_falses);
+       g_assert_cmpint (trues, ==, ret_trues);
+       g_assert_cmpint (falses, ==, ret_falses);
 }
 
-static gboolean
+static void
 test_md5sum (void)
 {
        GByteArray *data, *result;
@@ -195,7 +182,7 @@ test_md5sum (void)
        GValue retval;
        gboolean ok;
 
-       debug_printf (1, "md5sum (base64 -> base64): ");
+       debug_printf (1, "md5sum (base64 -> base64)\n");
 
        data = g_byte_array_new ();
        g_byte_array_set_size (data, 256);
@@ -213,21 +200,14 @@ test_md5sum (void)
              check_xmlrpc (&retval, SOUP_TYPE_BYTE_ARRAY, &result));
        g_byte_array_free (data, TRUE);
        if (!ok)
-               return FALSE;
-
-       if (result->len != digest_len) {
-               debug_printf (1, "result has WRONG length (%d)\n", result->len);
-               g_byte_array_free (result, TRUE);
-               return FALSE;
-       }
+               return;
 
-       ok = (memcmp (digest, result->data, digest_len) == 0);
-       debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!");
+       soup_assert_cmpmem (result->data, result->len,
+                           digest, digest_len);
        g_byte_array_free (result, TRUE);
-       return ok;
 }
 
-static gboolean
+static void
 test_dateChange (void)
 {
        GHashTable *structval;
@@ -236,7 +216,7 @@ test_dateChange (void)
        GValue retval;
        gboolean ok;
 
-       debug_printf (1, "dateChange (date, struct of ints -> time): ");
+       debug_printf (1, "dateChange (date, struct of ints -> time)\n");
 
        date = soup_date_new (1970 + (g_random_int_range (0, 50)),
                              1 + g_random_int_range (0, 12),
@@ -301,26 +281,24 @@ test_dateChange (void)
        g_hash_table_destroy (structval);
        if (!ok) {
                soup_date_free (date);
-               return FALSE;
+               return;
        }
 
        if (debug_level >= 2) {
                timestamp = soup_date_to_string (result, SOUP_DATE_ISO8601_XMLRPC);
-               debug_printf (2, "%s: ", timestamp);
+               debug_printf (2, "%s\n", timestamp);
                g_free (timestamp);
        }
 
-       ok = ((date->year   == result->year) &&
-             (date->month  == result->month) &&
-             (date->day    == result->day) &&
-             (date->hour   == result->hour) &&
-             (date->minute == result->minute) &&
-             (date->second == result->second));
+       g_assert_cmpint (date->year,   ==, result->year);
+       g_assert_cmpint (date->month,  ==, result->month);
+       g_assert_cmpint (date->day,    ==, result->day);
+       g_assert_cmpint (date->hour,   ==, result->hour);
+       g_assert_cmpint (date->minute, ==, result->minute);
+       g_assert_cmpint (date->second, ==, result->second);
+
        soup_date_free (date);
        soup_date_free (result);
-
-       debug_printf (1, "%s\n", ok ? "OK!" : "WRONG!");
-       return ok;
 }
 
 static const char *const echo_strings[] = {
@@ -338,15 +316,14 @@ static const char *const echo_strings_broken[] = {
        "amp; so is lt;thisgt;"
 };
 
-static gboolean
+static void
 test_echo (void)
 {
        GValueArray *originals, *echoes;
        GValue retval;
        int i;
-       gboolean php_bug = FALSE;
 
-       debug_printf (1, "echo (array of string -> array of string): ");
+       debug_printf (1, "echo (array of string -> array of string):\n");
 
        originals = g_value_array_new (N_ECHO_STRINGS);
        for (i = 0; i < N_ECHO_STRINGS; i++) {
@@ -360,7 +337,7 @@ test_echo (void)
                         G_TYPE_INVALID) &&
              check_xmlrpc (&retval, G_TYPE_VALUE_ARRAY, &echoes))) {
                g_value_array_free (originals);
-               return FALSE;
+               return;
        }
        g_value_array_free (originals);
 
@@ -369,37 +346,29 @@ test_echo (void)
                        debug_printf (2, "%s\"%s\"", i == 0 ? "[" : ", ",
                                      g_value_get_string (&echoes->values[i]));
                }
-               debug_printf (2, "] -> ");
+               debug_printf (2, "]\n");
        }
 
-       if (echoes->n_values != N_ECHO_STRINGS) {
-               debug_printf (1, " WRONG! Wrong number of return strings");
-               g_value_array_free (echoes);
-               return FALSE;
-       }
+       g_assert_cmpint (echoes->n_values, ==, N_ECHO_STRINGS);
 
        for (i = 0; i < echoes->n_values; i++) {
-               if (strcmp (echo_strings[i], g_value_get_string (&echoes->values[i])) != 0) {
-                       if (!server_test && strcmp (echo_strings_broken[i], g_value_get_string 
(&echoes->values[i])) == 0)
-                               php_bug = TRUE;
-                       else {
-                               debug_printf (1, " WRONG! Mismatch at %d\n", i + 1);
-                               g_value_array_free (echoes);
-                               return FALSE;
-                       }
+               if (!server_test && strcmp (echo_strings_broken[i], g_value_get_string (&echoes->values[i])) 
== 0) {
+                       /* We want to call g_test_skip(), but as of glib 2.38
+                        * that marks the test as failed rather than succeeded.
+                        */
+                       // FIXME g_test_skip ("PHP bug");
+                       g_value_array_free (echoes);
+                       return;
                }
+
+               g_assert_cmpstr (echo_strings[i], ==, g_value_get_string (&echoes->values[i]));
        }
 
-       if (php_bug)
-               debug_printf (1, "WRONG, but it's php's fault\n");
-       else
-               debug_printf (1, "OK!\n");
        g_value_array_free (echoes);
-       return TRUE;
 }
 
-static gboolean
-test_ping (gboolean include_params)
+static void
+test_ping (gconstpointer include_params)
 {
        GValueArray *params;
        GValue retval;
@@ -407,7 +376,7 @@ test_ping (gboolean include_params)
        char *out;
        gboolean ret;
 
-       debug_printf (1, "ping (void (%s) -> string): ",
+       debug_printf (1, "ping (void (%s) -> string)\n",
                      include_params ? "empty <params>" : "no <params>");
 
        params = soup_value_array_new ();
@@ -415,15 +384,15 @@ test_ping (gboolean include_params)
                                                 params->n_values);
        g_value_array_free (params);
        if (!request)
-               return FALSE;
+               return;
 
        if (!include_params) {
                char *params, *end;
 
                params = strstr (request, "<params/>");
                if (!params) {
-                       debug_printf (1, "ERROR: XML did not contain <params/>!");
-                       return FALSE;
+                       soup_test_assert (FALSE, "ERROR: XML did not contain <params/>!");
+                       return;
                }
                end = params + strlen ("<params/>");
                memmove (params, end, strlen (end) + 1);
@@ -433,21 +402,14 @@ test_ping (gboolean include_params)
        g_free (request);
 
        if (!ret || !check_xmlrpc (&retval, G_TYPE_STRING, &out))
-               return FALSE;
+               return;
 
-       if (!strcmp (out, "pong")) {
-               debug_printf (1, "OK!\n");
-               ret = TRUE;
-       } else {
-               debug_printf (1, "WRONG! Bad response '%s'", out);
-               ret = FALSE;
-       }
+       g_assert_cmpstr (out, ==, "pong");
 
        g_free (out);
-       return ret;
 }
 
-static gboolean
+static void
 do_bad_xmlrpc (const char *body)
 {
        SoupMessage *msg;
@@ -459,12 +421,7 @@ do_bad_xmlrpc (const char *body)
                                  body, strlen (body));
        soup_session_send_message (session, msg);
 
-       if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
-               debug_printf (1, "ERROR: %d %s\n", msg->status_code,
-                             msg->reason_phrase);
-               g_object_unref (msg);
-               return FALSE;
-       }
+       soup_test_assert_message_status (msg, SOUP_STATUS_OK);
 
        if (!soup_xmlrpc_parse_method_response (msg->response_body->data,
                                                msg->response_body->length,
@@ -474,44 +431,43 @@ do_bad_xmlrpc (const char *body)
                                      err->code, err->message);
                        g_error_free (err);
                        g_object_unref (msg);
-                       return TRUE;
+                       return;
                } else
-                       debug_printf (1, "ERROR: could not parse response\n");
+                       soup_test_assert (FALSE, "ERROR: could not parse response\n");
        } else
-               debug_printf (1, "Unexpectedly got successful response!\n");
+               soup_test_assert (FALSE, "Unexpectedly got successful response!\n");
 
        g_object_unref (msg);
-       return FALSE;
 }
 
-static gboolean
+static void
 test_fault_malformed (void)
 {
        debug_printf (1, "malformed request: ");
 
-       return do_bad_xmlrpc ("<methodCall/>");
+       do_bad_xmlrpc ("<methodCall/>");
 }
 
-static gboolean
+static void
 test_fault_method (void)
 {
        debug_printf (1, "request to non-existent method: ");
 
-       return do_bad_xmlrpc 
("<methodCall><methodName>no_such_method</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
+       do_bad_xmlrpc 
("<methodCall><methodName>no_such_method</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
 }
 
-static gboolean
+static void
 test_fault_args (void)
 {
        debug_printf (1, "request with invalid args: ");
 
-       return do_bad_xmlrpc 
("<methodCall><methodName>sum</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
+       do_bad_xmlrpc 
("<methodCall><methodName>sum</methodName><params><param><value><int>1</int></value></param></params></methodCall>");
 }
 
 static GOptionEntry xmlrpc_entries[] = {
-        { "uri", 'u', 0, G_OPTION_ARG_STRING, &uri,
+        { "uri", 'U', 0, G_OPTION_ARG_STRING, &uri,
           "Alternate URI for server", NULL },
-        { "server-test", 's', 0, G_OPTION_ARG_NONE, &server_test,
+        { "server-test", 'S', 0, G_OPTION_ARG_NONE, &server_test,
           "If this is being run from xmlrpc-server-test", NULL },
         { NULL }
 };
@@ -519,6 +475,8 @@ static GOptionEntry xmlrpc_entries[] = {
 int
 main (int argc, char **argv)
 {
+       int ret;
+
        test_init (argc, argv, xmlrpc_entries);
 
        if (!uri) {
@@ -528,31 +486,23 @@ main (int argc, char **argv)
 
        session = soup_test_session_new (SOUP_TYPE_SESSION_SYNC, NULL);
 
-       if (!test_sum ())
-               errors++;
-       if (!test_countBools ())
-               errors++;
-       if (!test_md5sum ())
-               errors++;
-       if (!test_dateChange ())
-               errors++;
-       if (!test_echo ())
-               errors++;
-       if (!test_ping (TRUE))
-               errors++;
-       if (!test_ping (FALSE))
-               errors++;
-       if (!test_fault_malformed ())
-               errors++;
-       if (!test_fault_method ())
-               errors++;
-       if (!test_fault_args ())
-               errors++;
+       g_test_add_func ("/xmlrpc/sum", test_sum);
+       g_test_add_func ("/xmlrpc/countBools", test_countBools);
+       g_test_add_func ("/xmlrpc/md5sum", test_md5sum);
+       g_test_add_func ("/xmlrpc/dateChange", test_dateChange);
+       g_test_add_func ("/xmlrpc/echo", test_echo);
+       g_test_add_data_func ("/xmlrpc/ping/empty-params", GINT_TO_POINTER (TRUE), test_ping);
+       g_test_add_data_func ("/xmlrpc/ping/no-params", GINT_TO_POINTER (FALSE), test_ping);
+       g_test_add_func ("/xmlrpc/fault_malformed", test_fault_malformed);
+       g_test_add_func ("/xmlrpc/fault_method", test_fault_method);
+       g_test_add_func ("/xmlrpc/fault_args", test_fault_args);
+
+       ret = g_test_run ();
 
        soup_test_session_abort_unref (session);
 
        test_cleanup ();
-       return errors != 0;
+       return ret;
 }
 
 #else /* HAVE_PHP_XMLRPC */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]