mayuki / Cocona

Micro-framework for .NET console application. Cocona makes it easy and fast to build console applications on .NET.
MIT License
3.26k stars 85 forks source link

CoconaApp.Run does not work in xunit/nunit #124

Open Zayik opened 8 months ago

Zayik commented 8 months ago

I created a .net 8.0 test project. Within that project, I included the latest Cocona package 2.2.0.

I then added the following test:

    public class UnitTest1
    {
        private readonly ITestOutputHelper output;

        public UnitTest1(ITestOutputHelper output)
        {
            this.output = output;
        }

        [Fact]
        public void RunCoconaApp()
        {
            output.WriteLine("Attempting to call CoconaApp.Run");
            CoconaApp.Run(
                () =>
                {
                    output.WriteLine("Hello World");
                });
        }
    }

Upon running this test, the only output seen is the initial line "Attempting to call CoconaApp.Run". Breakpointing into this test, I can hit the call to CoconaApp.Run, but the code within the lambda expression is never executed.

Expected behavior: CoconaApp.Run should work and execute the lambda expression when tested using xunit/nunit Actual behavior: CoconaApp.Run never executes the lambda expression when tested using xunit/nunit.

Had anyone successfully ran Cocona as part of their integration tests?

Puchaczov commented 3 weeks ago

This is something that is also pain for me, is there anybody who could share his reflections about what might be the problem here? My best guess for a quick look is that it runs with tests host and cocona might never be able to introduce itself properly to already configured host?