This directory contains unit tests for the core domain logic of the Conference Registration application using GoogleTest.
The test suite focuses on pure business logic without UI or Qt event loop dependencies. Tests are deterministic, fast, and run headlessly in CI.
- Basic construction and getters
- Empty and whitespace strings
- Special characters (unicode, accents)
- Long strings (boundary testing)
toString()formatting
- StandardRegistration: construction, fee calculation ($100), toString
- StudentRegistration: construction, fee calculation ($50 - 50% discount), qualification handling
- GuestRegistration: construction, fee calculation ($10 - 10% discount), category handling
- Booking date validation and edge cases
- Fee calculation consistency and ratios
- Singleton pattern verification
- Registration creation for all types (standard, student, guest)
- Case-insensitive type handling
- Invalid type handling (returns nullptr)
- Edge cases: empty strings, special characters, long strings, invalid dates
- Multiple registration creation
- CMake 3.5+
- C++17 compatible compiler
- Qt 5 or Qt 6 (Core module only)
- GoogleTest (automatically fetched via CMake FetchContent)
mkdir build && cd build
cmake ..
make unit_testscd build
ctest --output-on-failurecd build/tests/unit
./unit_tests./unit_tests --gtest_filter=PersonTest.*
./unit_tests --gtest_filter=RegistrationFactoryTest.CreateStandardRegistration*./unit_tests --gtest_verboseTests are automatically run in GitHub Actions on every pull request:
- name: Run unit tests
run: |
cd build
ctest --output-on-failure- Focused: Each test validates a single behavior
- Independent: Tests don't depend on each other
- Deterministic: No random data, no time-based dependencies
- Fast: All tests complete in < 1 second
- Clear: Descriptive test names and assertion messages
- Create a new test file in
tests/unit/(e.g.,myclass_test.cpp) - Add the file to
TEST_SOURCESintests/unit/CMakeLists.txt - Add any new source files to
CORE_SOURCESif needed - Follow existing naming conventions:
- Test file:
<class>_test.cpp - Test fixture:
<Class>Test - Test case:
<TestFixture>.<DescriptiveTestName>
- Test file:
#include "myclass.h"
#include <gtest/gtest.h>
class MyClassTest : public ::testing::Test {
protected:
void SetUp() override {
// Setup code
}
};
TEST_F(MyClassTest, DescriptiveTestName) {
// Arrange
MyClass obj("input");
// Act
auto result = obj.doSomething();
// Assert
EXPECT_EQ(result, expected);
}- These tests do not cover:
- UI components (Qt Widgets)
- File I/O operations
- Qt Model/View classes
- Serialization logic
These areas require separate integration or functional tests.