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

Is it possible to use this Test engine for integration tests? #37

Open
GasimGasimzada opened this issue Nov 18, 2023 · 2 comments
Open

Comments

@GasimGasimzada
Copy link

Does the backend or something matter for ImGui to work in this case? I want to somehow run Imgui tests using Google test but in an integration way where the real application is not running but I am calling Imgui to render the UI and then automatically clicking buttons etc and checking the results.

@ocornut
Copy link
Owner

ocornut commented Dec 13, 2023

I'm not sure I understand the question but the answer is probably yes.

where the real application is not running

The real application needs to be running, it's the one submitting ImGui widgets.
But you may use a "headless" application, aka one with no visible rendering context.

@GasimGasimzada
Copy link
Author

GasimGasimzada commented Dec 23, 2023

Basically, instead of running the full application that is very heavy in terms of all the functionality it has, I want to test each part of the application in isolation. In terms of testing strategy, instead of using E2E tests where the whole application is being run, I want to do integration tests where I mock some of the services that are not necessary for the UI (e.g Physics engine).

This is the type of test that I want to write (using GoogleTest):

// Function that I want to test
void renderEntityPanel(EntityDatabase &db, Entity entity) {
  If (Imgui::Begin("Entity panel")) {
    if (ImGui::Button("Add animator")) {
      db.set(entity, Animator{});
    }
    ImGui::End();
  }
}

TEST_F(EntityPanelTest, ClickingAddAnimatorCreatesAnimatorComponent) {
      auto imTest = IM_REGISTER_TEST(engine, "Tests", "test");
      imTest->TestFunc = [](auto *ctx) {
         ctx->SetRef("Entity panel");
         ctx->ItemClick("Add Animator");
      };

      EntityDatabase db;
      auto entity = db.create();

      ImGui::NewFrame();
      renderEntityPanel(db, entity);
      Imgui::Render();

      // I want to run the test function right here
      imTest->RunTestFunction();

      // Do I need to call `renderEntityPanel` again for the button to be registered?
      EXPECT_TRUE(db.has<Animator>(entity));
}

I have couple of questions to be able to achieve this:

  1. How can programatically run a registered test?

  2. In order to get this working, do I need to call

    ImGui::NewFrame();
    renderEntityPanel(db, entity);
    Imgui::Render();

    after the test function is run?

  3. Is there a guarantee that after a test function is run with item being clicked, if (ImGui::Button("Add animator")) condition will be true in the next frame?

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

No branches or pull requests

2 participants