Home

LinqPad 6 and xUnit test framework

I can use xUnit with xUnit test runner successfully with LinqPad 5, but it fails to run with LinqPad 6. Details can be found at StackOverflow. Trying to replace the xUnit by a .NET Core version didn't help, the issue seems to be with the test runner. How can that be fixed?

Comments

  • Hi!, you can try the following solution, https://stackoverflow.com/a/61846576/1856914. It works with Linqpad6 + NetCore

  • edited May 18

    This is a good use-case. I will be adding explicit support for xunit soon, to make this easier.

  • @JoeAlbahari - Good to hear, that sounds great! Looking forward ... ;-)

    Meanwhile, I updated my answer at StackOverflow - thank you @uliseo for the hint regarding the test runner.

    I tried to explain it detailed - for LinqPad 5 and LinqPad 6 as well, which will help you support your use case.
    On my PC both versions are running fine now.

    Cheers, Matt

  • Try the latest LINQPad 6 beta:
    https://www.linqpad.net/linqpad6.aspx#beta

    It now has an option on the query menu to add xunit integration. This works by adding #load xunit to the current query, along with a sample test method and a call to RunTests() in the main method.

    The xunit.linq file is created automatically on first use, and contains the xunit runner code, as well as the references to the xunit nuget packages. You can modify this query to customize the test runner.

    I've made a couple of changes to LINQPad's execution engine to make this work. First, the LINQ-to-SQL and EF Core data context drivers now expose a parameterless constructor in the containing UserQuery class (which implicitly pick up the query's connection properties). This allows xunit to construct instances of UserQuery in queries that have a data context, thereby letting you define test methods directly in the query rather than needing a separate class.

    Second, the #load resolution mechanism now identifies regions whose name starts with private:: and strips them out before merging the query. This lets you ensure that your unit tests don't get exported should the query itself be #load-ed.

    Let me know how you get along.

Sign In or Register to comment.