Invvard
Invvard

Reputation: 2057

xUnit tests with Azure Functions SDK are not working

I'm trying to unit test an Azure Functions project, but I ran into this issue : as soon as I install the Microsoft.NET.Sdk.Functions NuGet package, output directory for the DLL is changed to a sub /bin dir and xUnit runner is unable to find the test DLLs anymore.

Here are the steps to reproduce :

  1. Create a new solution with a xUnit project only (let's name it "xUnitTests"),
  2. Just put a Assert.True(true); in the created unit test,
  3. Run the test : everything goes smoothly and test is valid,
  4. Now add the Microsoft.NET.Sdk.Functions NuGet package and run the test,
  5. This time it is ignored...

From what I get from logs is that the build output directory is changed from

$(SourceDirectory)\xUnitTests\xUnitTests\bin\Debug\netcoreapp3.1\

to

$(SourceDirectory)\xUnitTests\xUnitTests\bin\Debug\netcoreapp3.1\bin\

So xUnit.runner.visualstudio doesn't find the xUnitTests.dll as it continues to look after it in the first directory and not in the new .\bin one...

Anybody has an explanation, solution or work around ? (except copying the whole directory to the expected location with an after build event)

Thank you for you help and your time.

Upvotes: 0

Views: 543

Answers (1)

HariHaran
HariHaran

Reputation: 4199

Now add the Microsoft.NET.Sdk.Functions NuGet package and run the test

AFAIK, you should not add the Microsoft.NET.Sdk.Functions package to your xUnit project. Instead, follow the below steps.

  • You already have an existing Azure Function project.
  • Create a new xUnit test project.
  • Now add the function project as a reference to your test project.
  • Now you can write tests based on your use cases.

Resources :

Medium

Docs

Upvotes: 2

Related Questions