I would like to create a test suite for my C++ wxWidgets app and am having trouble with figuring out how to test GUI components. The article in the docs about how to write unit tests is written from the perspective of augmenting the existing unit tests but doesn't address how to start new ones.
I was able to create a test suite using Catch (which appears to be the recommended approach) but am having trouble getting started on the GUI side.
On the non-GUI side, I created a test that looks like this
#include "catch.hpp"
#include "wx/wx.h"
TEST_CASE("wx", "[wx]") {
wxPoint p = wxPoint(10, 10);
REQUIRE(p.x == 10);
}
and a CMakeLists file that looks like this (just the relevant section):
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wxWidgets/3rdparty/catch/include/)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
# Make test executable
set(TEST_SOURCES
test.cpp
)
add_executable(tests ${TEST_SOURCES})
target_link_libraries(tests Catch ${wxWidgets_LIBRARIES})
And this worked just fine. So there is no problem linking against the wxWidgets libraries. I believe the problem is in creating a wxApp or an event loop. But I'm unsure of how to rectify that.
When I create a test that attempts to create a button (like in buttontest.cpp
that is suggested in the docs to use as an example), I receive a Segmentation violation signal
.
TEST_CASE("wx", "[wx]") {
wxButton* button = new wxButton(wxTheApp->GetTopWindow(), wxID_ANY, "wxButton");
wxYield();
}
Is there a place that demonstrates how to create GUI tests for wxWidgets from scratch instead of just adding to the wxWidgets tests themselves?