Skip to content

Tests may behave differently in Release configuration #326

Closed

Description

@timbussmann

I've noticed that some tests which fail in Debug configuration no longer fail in our CI pipeline as the tests in the pipeline are running in Release configuration. Code optimizations applied in release config can lead to validations not properly working anymore.

I have a demo repro available here: https://github.com/timbussmann/ArchUnitNetRepro:

The problem is that due to async state machine optimizations, this code:

public async Task DoSomethingAsync()
    {
        await service.SomeAsyncMethod();
    }

does not violate the following assertion anymore since the actual call has been extracted into the async state machine:

Classes().Should().NotCallAny(MethodMembers().That().AreDeclaredIn(typeof(ExampleService)))

I'm aware that this isn't necessarily ArchUnit.NET's fault, but it's a problem one can easily run into without noticing for a long time, making the tests less useful.

Activity

  1. alexanderlinne commented on Mar 3, 2025

    @alexanderlinne
    Collaborator

    Hi @timbussmann, thank you for your example repository. Yes, it is known that some rules may not work exactly the same in debug and release. I've created a pull request to include an example similar to yours in the example project and update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

kind/supportCategorizes issue or PR as a support question.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions