Unit test URLConnection


I wanted to know if it’s possible to test for Desktop application (using Xojo Unit) external api endpoints with URLConnection in an async way but where the second routes wait for the first to end.

Or do I have to run URLConnection in sync mode ? (even with that I did not succeed in writing tests for API endpoints)


  • Route 1: POST /api/login
  • Route 2: (wait for route 1 to end) GET /api/users

Does anyone performed this already?

Thank you,


Yes, XojoUnit has async functions.

Set up your URLConnection as a property and use AddHandler to handle its event. In the main test function, end with AsyncAwait secs // # of seconds to wait. In the event handler, call AsyncComplete, and remember to tear down the handler for URLConnection somewhere.

Note: if an exception occurs in a method that is being called asynchronously, and you don’t catch it, XojoUnit will die an inglorious death.

I believe I included an example of this in the standard unit tests that come with the project.

Ok I will try to look into that and follow your explanation.

There is an async test method in the project but nothing using URLConnection, if anyone has an example using URLConnection, I would like to see how it’s working

Thank you