Skip to content

Conversation

Copy link

Copilot AI commented Sep 21, 2025

This PR implements the transition from the existing custom assert-based testing framework to Catch2, a modern C++ testing framework, as requested in issue #18.

What's Changed

The project now uses Catch2 v2.13.10 as the primary testing framework while maintaining full backward compatibility with the existing test suite. All original test functionality has been preserved and enhanced with better organization and reporting.

New Testing Structure

  • Catch2 Integration: Downloaded and integrated the single-header Catch2 library (test/lib/catch2.hpp)
  • Organized Test Suite: Created test/test_microbiome.cpp with all tests converted to Catch2 format
  • Tagged Tests: Tests are now organized with descriptive tags for easy filtering:
    • [appconfig] - Configuration validation tests
    • [microorganism] - Microorganism behavior tests
    • [factory] - MicroorganismFactory tests
    • [microbiome] - Microbiome management tests
    • [simulation] - Simulation execution tests

Enhanced Build System

The Makefile has been updated with new targets while preserving existing functionality:

make catch2_tests  # Build Catch2 tests (new primary method)
make test          # Alias for catch2_tests
make tests         # Legacy tests (backward compatibility)

Improved Developer Experience

Catch2 provides significant improvements over the previous assert-based approach:

Better Error Reporting:

FAILED:
  REQUIRE( actual == expected )
with expansion:
  41 == 42

Selective Test Execution:

./mb_tests [microorganism]    # Run only microorganism tests
./mb_tests [simulation]       # Run only simulation tests
./mb_tests --list-tests       # Show all available tests

Enhanced Output Options:

./mb_tests --success          # Show detailed success information
./mb_tests --reporter junit   # Generate JUnit XML for CI/CD

Backward Compatibility

  • Legacy test system remains fully functional via make tests
  • All existing test logic preserved unchanged
  • No breaking changes to existing workflows
  • run_tests.sh updated to run both test systems for comparison

Test Coverage

All original tests have been successfully migrated:

  • AppConfig: Setters and getters validation
  • Microorganism: Energy consumption, movement tracking, consumption tracking
  • MicroorganismFactory: ID generation verification
  • Microbiome: Entity management and microorganism lifecycle
  • Simulation: Creation, execution, and result consistency

Result: 10 test cases with 26 assertions - all passing ✅

Documentation Updates

  • Updated README.md with comprehensive Catch2 usage guide
  • Added examples for test filtering and advanced features
  • Documented both new and legacy test commands
  • Updated .gitignore to exclude new build artifacts

This transition provides a solid foundation for future test development with industry-standard tooling while ensuring zero disruption to existing development workflows.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits September 21, 2025 16:04
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copilot AI changed the title [WIP] @Preponderous-Software/microbiome/issues/18 Transition testing framework from custom assert-based tests to Catch2 Sep 21, 2025
@dmccoystephenson dmccoystephenson marked this pull request as ready for review September 21, 2025 16:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Migrates the test suite from custom asserts to Catch2 and updates build and docs to make Catch2 the primary testing path while keeping legacy tests available.

  • Integrates Catch2 header and adds a consolidated Catch2 test file
  • Updates Makefile with a new catch2_tests target and test alias; updates run_tests.sh to run Catch2 and legacy tests
  • Refreshes README with Catch2 usage and commands

Reviewed Changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 7 comments.

File Description
test/test_microbiome.cpp New Catch2-based test suite covering AppConfig, Microorganism, MicroorganismFactory, Microbiome, and Simulation
Makefile Adds catch2_tests target, test alias to Catch2, and clean rule; preserves legacy tests
run_tests.sh Builds and runs Catch2 tests, then runs legacy tests; cleans old binaries before running
README.md Documents Catch2 as primary framework, commands, and features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +141 to +143
if (config.getMaxTicks() > 0) {
REQUIRE(simulation.getTicksElapsed() >= config.getMaxTicks());
}
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion is inverted for a freshly constructed Simulation: ticksElapsed should be 0 before run() is called, not >= maxTicks. Replace with REQUIRE(simulation.getTicksElapsed() == 0); If the goal is only to ensure it hasn't exceeded the max, use REQUIRE(simulation.getTicksElapsed() <= config.getMaxTicks()).

Suggested change
if (config.getMaxTicks() > 0) {
REQUIRE(simulation.getTicksElapsed() >= config.getMaxTicks());
}
REQUIRE(simulation.getTicksElapsed() == 0);

Copilot uses AI. Check for mistakes.
microbiome.addMicroorganism(microorganism);

// Verify presence
REQUIRE(microbiome.isMicroorganismPresent(microorganism.getId()) == true);
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Prefer idiomatic Catch2 assertions over comparing to true/false. For example: 29: REQUIRE(config.isSimulationOutputEnabled()); 115: REQUIRE(microbiome.isMicroorganismPresent(microorganism.getId())); 121: REQUIRE_FALSE(microbiome.isMicroorganismPresent(microorganism.getId())); 131: REQUIRE_FALSE(microorganismFound);

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +4
# Remove old executables
rm -f ./tests ./mb_tests

# compile
make tests
# Compile Catch2 tests (default)
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Add a shebang and strict mode to make the script fail fast and be more robust. Suggested header: #!/usr/bin/env bash followed by set -euo pipefail.

Copilot uses AI. Check for mistakes.
Comment on lines +14 to 16
echo "Running legacy tests for comparison..."
make tests
./tests
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says 'Optionally' but the script always runs legacy tests. Either update the comment or gate these lines behind a flag, e.g.: if [ "${RUN_LEGACY:-0}" = "1" ]; then ... fi.

Suggested change
echo "Running legacy tests for comparison..."
make tests
./tests
if [ "${RUN_LEGACY:-0}" = "1" ]; then
echo "Running legacy tests for comparison..."
make tests
./tests
fi

Copilot uses AI. Check for mistakes.
@@ -10,5 +11,16 @@ all: mbapp tests
mbapp: src/mbapp.cpp
g++ $(WARNING_FLAGS) $(MAIN_FILE) $(PROJECT_FILES) $(ENVLIBCPP_FILES) -o mb_app
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Specify the C++ standard explicitly to ensure consistent builds across environments (Catch2 v2 requires C++11+). For example, add -std=c++17 to these compile commands, or define CXXFLAGS = -std=c++17 $(WARNING_FLAGS) and reuse it.

Copilot uses AI. Check for mistakes.
# Legacy tests (for backward compatibility)
tests: src/tests.cpp
g++ $(WARNING_FLAGS) $(PROJECT_FILES) $(ENVLIBCPP_FILES) $(TESTS_FILE) -o tests No newline at end of file
g++ $(WARNING_FLAGS) $(PROJECT_FILES) $(ENVLIBCPP_FILES) $(TESTS_FILE) -o tests
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Specify the C++ standard explicitly to ensure consistent builds across environments (Catch2 v2 requires C++11+). For example, add -std=c++17 to these compile commands, or define CXXFLAGS = -std=c++17 $(WARNING_FLAGS) and reuse it.

Copilot uses AI. Check for mistakes.

# Catch2 tests (new)
catch2_tests: test/test_microbiome.cpp
g++ $(WARNING_FLAGS) -I test $(PROJECT_FILES) $(ENVLIBCPP_FILES) $(CATCH2_TEST_FILE) -o mb_tests
Copy link

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Specify the C++ standard explicitly to ensure consistent builds across environments (Catch2 v2 requires C++11+). For example, add -std=c++17 to these compile commands, or define CXXFLAGS = -std=c++17 $(WARNING_FLAGS) and reuse it.

Copilot uses AI. Check for mistakes.
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.

2 participants