Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GD-154: Add new assert_func with a wait_until(<time>) to wait for a specific return value #159

Merged
merged 11 commits into from
Oct 1, 2021

Conversation

MikeSchulze
Copy link
Owner

No description provided.

@MikeSchulze MikeSchulze added this to the v1.0.6 milestone Sep 18, 2021
@MikeSchulze MikeSchulze self-assigned this Sep 18, 2021
@derkork
Copy link
Contributor

derkork commented Sep 20, 2021

Mhh, it sure works. But I think it doesn't really integrate well into the scene runner, which would allow you to run scenes at faster speeds. So now I need to decide if I want to have a timed assert or a faster run, I can't have both currently. If I use the scene runner, I need a signal or simulate a certain amount of frames, but cannot wait for a condition to be true. If I use the new assert, I can only run at normal speed. I think the separation of the scene runner and asserts doesn't help a lot with integration tests. In integration tests you very often have to wait on a certain thing to happen and this wait almost always also serves as an assert (because if the thing doesn't happen, the next thing usually makes no sense to run anyways).

I wonder if this could be solved by having two classes for two types of tests. I would argue that you will need the runner in integration tests, only but not in unit tests. So you could have GdUnitTestSuite for unit tests and GdIntegrationTestSuite for integration test. The latter could replace GdUnitSceneRunner and you could then write integration tests like this:

class_name SomeIntegrationTest
extends GdIntegrationTestSuite

var _scene
var _driver

func before_test():
        _scene = load(..).instance()
        _driver = GameDriver.new()
        # this would be the equivalent of creating a new scene runner
        # it would be a function of the new GdIntegrationTestSuite class
        attach_scene(scene)  
        # run everything at 3x speed
        set_time_factor(3)
        # set a default timeout for all timed assertions
        set_default_assertion_timeout(3000)
   
func after_test():
       # would free the scene node so next test starts with a fresh one
       free_scene() 

func test_something():
        # when
        simulate_mouse_click(...)
        # then
        # wait until a dialog is shown
        yield(assert_func(_driver.some_dialog, "is_present").is_true())

         # abort test if an error occurred
         if has_error():
             return 

          # when
         _driver.car.move()
         # then
         # wait until the car sends the "crashed" signal.
         yield(assert_signal(_driver.car.get(), "crashed").is_sent())

Of course this is a breaking change 😢 I'm sorry I didn't think of this earlier.

@MikeSchulze
Copy link
Owner Author

Mhh, it sure works. But I think it doesn't really integrate well into the scene runner, which would allow you to run scenes at faster speeds. So now I need to decide if I want to have a timed assert or a faster run, I can't have both currently. If I use the scene runner, I need a signal or simulate a certain amount of frames, but cannot wait for a condition to be true. If I use the new assert, I can only run at normal speed. I think the separation of the scene runner and asserts doesn't help a lot with integration tests. In integration tests you very often have to wait on a certain thing to happen and this wait almost always also serves as an assert (because if the thing doesn't happen, the next thing usually makes no sense to run anyways).

I wonder if this could be solved by having two classes for two types of tests. I would argue that you will need the runner in integration tests, only but not in unit tests. So you could have GdUnitTestSuite for unit tests and GdIntegrationTestSuite for integration test. The latter could replace GdUnitSceneRunner and you could then write integration tests like this:

class_name SomeIntegrationTest
extends GdIntegrationTestSuite

var _scene
var _driver

func before_test():
        _scene = load(..).instance()
        _driver = GameDriver.new()
        # this would be the equivalent of creating a new scene runner
        # it would be a function of the new GdIntegrationTestSuite class
        attach_scene(scene)  
        # run everything at 3x speed
        set_time_factor(3)
        # set a default timeout for all timed assertions
        set_default_assertion_timeout(3000)
   
func after_test():
       # would free the scene node so next test starts with a fresh one
       free_scene() 

func test_something():
        # when
        simulate_mouse_click(...)
        # then
        # wait until a dialog is shown
        yield(assert_func(_driver.some_dialog, "is_present").is_true())

         # abort test if an error occurred
         if has_error():
             return 

          # when
         _driver.car.move()
         # then
         # wait until the car sends the "crashed" signal.
         yield(assert_signal(_driver.car.get(), "crashed").is_sent())

Of course this is a breaking change 😢 I'm sorry I didn't think of this earlier.

Thanks for your feedback.
Yes the assert_func not respects the time factor, good catch +1
I love the idea to have a extra GdUnitIntegrationTestSuite, in general i agree we should think in category unit and integration tests.
So to have two test-suites types, unit and integration makes totally sense, i love this suggestion.

The new assert_func will respect time factor if set on next iteration.

For integrate integration tests stuff i will create a new feature request.
Very good feedback, Thanks so much

@MikeSchulze
Copy link
Owner Author

to continue i will provide a function on the SceneRunner where at least wraps around the assert_func to respect the time factor.

MikeSchulze and others added 9 commits September 26, 2021 09:30
- better assert failure line number detection
- improve test coverage for GdUnitFuncAssert
- fix timeout issues during wait assser completion
fix many issues wiht assert_func and yielding
added assert_func to scene runner
- still problems with orphan nodes
fix orphans
@MikeSchulze MikeSchulze merged commit 072b3dc into master Oct 1, 2021
@MikeSchulze MikeSchulze deleted the GD-154 branch October 1, 2021 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GD-154: new assert_func with a wait_until(<time>) to wait for a specific return value
2 participants