Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE]: Better logging support for xUnit #227

Closed
2 tasks done
thePantz opened this issue Dec 4, 2022 · 7 comments
Closed
2 tasks done

[FEATURE]: Better logging support for xUnit #227

thePantz opened this issue Dec 4, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@thePantz
Copy link

thePantz commented Dec 4, 2022

Description

XUnit v2 does not support the use of Console, Debug, Trace

If you used xUnit.net 1.x, you may have previously been writing output to Console, Debug, or Trace. When xUnit.net v2 shipped with parallelization turned on by default, this output capture mechanism was no longer appropriate; it is impossible to know which of the many tests that could be running in parallel were responsible for writing to those shared resources.

This means that Boa.Constrictors built in ConsoleLogger will not work for xUnit.
I suggest we implement a new logger that will work with xUnits logging interface(s) as described here: https://xunit.net/docs/capturing-output

Alternatives

Switching to NUnit/MsTest

Anything else?

Should be pretty straight forward to implement support for ITestOutputHelper. It functions similarly to Console but would require an instance provided by xUnit.

There may be some limitations with setting up Actors in Class Fixtures since they won't have access to ITestOutputHelper from that context

Commitments

  • I agree to follow Boa Constrictor's Code of Conduct.
  • I want to work on this issue myself. (This is voluntary, not required.)
@thePantz thePantz added the enhancement New feature or request label Dec 4, 2022
@thePantz
Copy link
Author

thePantz commented Dec 5, 2022

The solution to this is the following:

public class XUnitLogger : AbstractLogger
{
      private readonly ITestOutputHelper output;

      public XUnitLogger(ITestOutputHelper output, LogSeverity severity = LogSeverity.Trace)
          :base(severity)
      {
          this.output = output;
      }

      public override void Close()
      {
          // This logger needs no closing
      }

      protected override void LogRaw(string message, LogSeverity severity = LogSeverity.Info)
      {
          if(severity >= LowestSeverity)
              output.WriteLine(message);
      }
}

public class MyTest
{
        private readonly ITestOutputHelper output;
        public MyTest(ITestOutputHelper output)
        { 
            this.output = output;
        }

        [Fact]
        public void EditIcon_ShouldPutRowInEditMode()
        {
            var test = new Actor("Customer", new XUnitLogger(output));
        }
}

Given the recent architecture changes, where should I place this? At first I considered placing this under Boa.Constrictor.Screenplay however it would require adding an xUnit dependency. Would it be more appropriate to start a Boa.Constrictor.xUnit project?

@AutomationPanda
Copy link
Contributor

@thePantz, this is good stuff. You're absolutely right about the dependency issue. I think I agree with your assessment that we'd want a separate project and package for xUnit to support this.

My questions for you:

  • Is this something you'd want to do?
  • Do you want this to be part of the main Boa Constrictor repository?

I'd love to collaborate with you on this if you're up for the challenge!

@thePantz
Copy link
Author

thePantz commented Dec 8, 2022

Yes! I would be happy to contribute! I figure it's a general enough use case that will be useful to others.

Although, I noticed #20 the other day and was wondering if this is still valuable or if it will soon be obsolete

@AutomationPanda
Copy link
Contributor

#20 is still valid but not planned at the moment. I'd say move forward with this xUnit logger for now. We can change things in the future.

@AutomationPanda
Copy link
Contributor

@thePantz feel free to fork the repository, get working, and send a pull request!

@AutomationPanda
Copy link
Contributor

(I'm here to answer questions and offer help along the way if you need it, too!)

@thePantz thePantz mentioned this issue Dec 13, 2022
6 tasks
@AutomationPanda
Copy link
Contributor

This work was completed as part of #248 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants