Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 15, 2025

This PR updates the Logback smoke tests to use the new assertion framework introduced in #4141 and extends the framework to support MessageData and ExceptionData assertions.

Changes Made

Framework Extensions

  1. Added MessageAssert class - Provides fluent assertions for MessageData with methods like:

    • hasMessage() - Assert message content
    • hasSeverityLevel() - Assert severity level
    • hasProperty() - Assert properties
    • hasPropertiesSize() - Assert property count
  2. Added ExceptionAssert class - Provides fluent assertions for ExceptionData with methods like:

    • hasExceptionType() - Assert exception type
    • hasExceptionMessage() - Assert exception message
    • hasSeverityLevel() - Assert severity level
    • hasEmptyProperties() - Assert no properties (for non-logger exceptions)
  3. Extended TraceAssert - Added support for:

    • hasMessageSatisying() - Assert message data in trace
    • hasExceptionCount() - Assert exception count
    • hasExceptionSatisying() - Assert exception data in trace

Test Updates

LogbackTest.java

  • Converted test() method to use new framework for asserting message data
  • Converted testWithException() method to use new framework for asserting exception data
  • Maintained conditional logic for Wildfly vs non-Wildfly server differences

LogbackDisabledTest.java & LogbackLevelOffTest.java

  • Updated both test methods to use new assertion framework
  • Simplified exception handling using new ExceptionAssert class

Benefits

  • Cleaner test code: Removes manual casting and envelope extraction
  • Better readability: Fluent API makes test intentions clearer
  • Consistent with framework: Aligns with the assertion pattern used in other tests
  • Maintainable: Centralized assertion logic in reusable classes

Example Usage

Before:

List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1);
Envelope rdEnvelope = rdList.get(0);
RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
assertThat(rd.getName()).isEqualTo("GET /Logback/test");

After:

testing.waitAndAssertTrace(trace -> 
    trace.hasRequestSatisying(request -> 
        request.hasName("GET /Logback/test").hasSuccess(true)));

The tests now use the same modern assertion framework introduced in #4141, making them more maintainable and consistent with the rest of the codebase.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Update the Logback smoke test to use the new assertion framework introduced in @microsoft/ApplicationInsights-Java/pull/4141 Extend the assertion framework if needed. Run the Logback smoke test after making your changes to ensure it is still passing. ... Update Logback smoke tests to use new assertion framework and extend framework for MessageData and ExceptionData Jul 15, 2025
Copilot AI requested a review from trask July 15, 2025 01:03
@trask
Copy link
Member

trask commented Jul 15, 2025

LogbackDisabledTest and LogbackLevelOffTest are failing

Note: Generally you shouldn't run all of the smoke tests, as they can take a long time.
Instead, focus on running a single test.

# Run a specific smoke test
./gradlew :smoke-tests:apps:HttpClients:smokeTest --tests "*HttpClientTest\$Tomcat8Java8Test"

Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

LogbackDisabledTest and LogbackLevelOffTest are failing

Note: Generally you shouldn't run all of the smoke tests, as they can take a long time.
...

Fixed the failing LogbackDisabledTest and LogbackLevelOffTest. The issue was that the tests were expecting .hasSuccess(true) but the /testWithSpanException endpoint returns a 500 error code (making success=false) because it throws a RuntimeException. Updated both tests to expect .hasSuccess(false) instead. (b5c093d)

@trask trask closed this Jul 15, 2025
@trask trask deleted the copilot/fix-2b0040d1-6268-4792-9cc5-97a6772ffd8f branch July 23, 2025 01:15
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