DAndrewBox / GM-Testing-Library

An open-source testing framework for GameMaker libraries, extensions and (hopefully) prefabs, with a focus on simplicity and ease of use.
MIT License
16 stars 0 forks source link

Question: examples for testing async functions? #1

Open shichen85 opened 3 months ago

shichen85 commented 3 months ago

Hello, thanks for the well-documented project! A quick question: do you have any examples for testing async functions such as http_get() or buffer_save_async(), where the response comes back a few frames later in the Async event?

DAndrewBox commented 3 months ago

@shichen85 Thank you for the input! Right now it has no support for E2E tests related to http requests or code using the async event since I haven't found a way to simulate in one frame the async_load you should receive outside the async events, but it's on my backlog and was an idea that I had during the first iterations.

Hopefully I'll be able to implement it for later releases, I will tag this issue/question when that happens!

shichen85 commented 3 months ago

@shichen85 Thank you for the input! Right now it has no support for E2E tests related to http requests or code using the async event since I haven't found a way to simulate in one frame the async_load you should receive outside the async events, but it's on my backlog and was an idea that I had during the first iterations.

Hopefully I'll be able to implement it for later releases, I will tag this issue/question when that happens!

Thanks for the reply!

I have never not thought about using synchronous simulations to test async logics before, but after taking a look at your implementation of GMTL_core_test_events I can see how that can work, and it is very inspiring! Perhaps using event_perform_async followed by event_perform_object on an object that is meant to handle async events could achieve the purpose.

Testing async logic has long been my desire, but it took me a while to figure out how to support them in GML. I eventually developed a testing GML library called Olympus that was inspired by MochaJS, and I structured each test/it block to behave like a Javascript Promise so that I could wait for them to resolve or reject and pass the result back to test/it block to analyze and match. Here is an example of testing http_get. I am mostly happy with the implementation and have been using that to test various async functions or objects in my runtime test suite, but I think the function signature is still hard to reason through for first time users.

Anyways, I am very excited for more discussions on testing in the GML space. Hit me up if you ever want to talk more on it!