Getting a "could not be found" from the unit test project - Microsoft Q&A (2024)

Generally you get this when the previous project fails to build. Try a clean build. Also ensure that you're using a project reference to the other project and not a binary reference. There is also the chance that it is related to using different target frameworks but you'd have to identify what changed between the working and non-working versions.

  1. Getting a "could not be found" from the unit test project - Microsoft Q&A (1)

    Rod At Work 866Reputation points

    2022-05-25T21:42:42.403+00:00

    Thank you, @Michael Taylor , for your response,

    I've tried at least three clean builds, but that didn't help.

    I've just double checked the xUnit test project. It has a project reference to the MVC project.

    I've just checked both projects. They're both using .NET 6.

    Thank you very much for making suggestions as to what I should check to help resolve this issue. Have you other suggestions?

  2. Getting a "could not be found" from the unit test project - Microsoft Q&A (2)

    Michael Taylor 52,721Reputation points

    2022-05-25T21:53:13.107+00:00

    When the error occurs is the file actually on disk where it is looking for it? I'm assuming it is building successfully and that the build order is correct.

    Do you have the latest test framework and test adapter installed for xUnit?

    Turn on diagnostic debugging for the MSBuild and take a look at the build output for the test project. You're looking for warnings and errors.

  3. Getting a "could not be found" from the unit test project - Microsoft Q&A (3)

    Rod At Work 866Reputation points

    2022-05-25T22:11:49.007+00:00

    The .DLL is not in the folder where the test project is looking for it. That is significant. However, I would have expected MSBuild to "know" what order it should build the projects in: MVC project first, then the unit test project. After all, if there's anything like a MAKEFILE, I've no idea what that would be, for MSBuild. What I did was modify a view, a viewmodel class and the associated controller. Why that would make a difference to how MSBuild performs a build, when it never was a problem before, is a huge mystery to me.

    There's an update to xUnit (also one for Moq, Microsoft.NET.Test.Sdk and something called coverlet.collector). I'll update the xUnit project, then let you know how it went...

    ... unfortunately, that didn't change anything.

    Lastly, I've no idea how to turn on diagnostic debugging for MSBuild. How do I do that?

  4. Getting a "could not be found" from the unit test project - Microsoft Q&A (4)

    Michael Taylor 52,721Reputation points

    2022-05-26T14:31:40.323+00:00

    MSBuild compiles in the order given. If you have a project reference then the order will have the dependent project built after the dependee but you can verify the ordering by right clicking the solution in Solution Explorer and looking at the build order. But I doubt that it is an issue here.

    I'm assuming here the build for PharmacyWarehouseV2 is successful. Can you post the top level items from your project file for the MVC project and all the xUnit test project file contents? I'm curious if there is a mismatch somewhere.

    Alternatively create a new xUnit test project, add a dependency to the MVC project and compile. If that works then move your tests to the new project and try again.

  5. Getting a "could not be found" from the unit test project - Microsoft Q&A (5)

    Rod At Work 866Reputation points

    2022-05-26T20:06:42.317+00:00

    (I'm going to have to do this in multiple replies, because I've exceeded the character limit)

    Thank you for pointing out the "Project Build Order..." option when right-mouse button clicking on the solution. I did that and verified that the build order is correct.

    I guess PharmacyWarehouseV2 built successfully. When I did a Build Clean and rebuild solution, there was only one error, which is in PharmacyWarehouseV2.Test. However, that's because there is no .DLL located at C:\Repos\PW\PharmacyWarehouseV2\PharmacyWarehouseV2\obj\Debug\net6.0\ref\PharmacyWarehouseV2.dll. In fact, I just searched throughout the PharmacyWarehouseV2 project directory structure. There's no .DLL anywhere.

    Here's the top level items, including the PropertyGroup, from the PharmacyWarehouseV2

  6. Getting a "could not be found" from the unit test project - Microsoft Q&A (6)

    Rod At Work 866Reputation points

    2022-05-26T20:07:53.507+00:00

    <Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="KendoUIProfessional" Version="2022.1.412" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.2" />

  7. Getting a "could not be found" from the unit test project - Microsoft Q&A (7)

    Rod At Work 866Reputation points

    2022-05-26T20:08:20.847+00:00

    And here is PharmacyWarehouseV2.Test project file:

    <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>

    <IsPackable>false</IsPackable> 

    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="Moq" Version="4.17.2" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.0">
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    </ItemGroup>

    <ItemGroup>
    <ProjectReference Include="..\PharmacyWarehouseV2\PharmacyWarehouseV2.csproj" />
    </ItemGroup>

    </Project>

  8. Getting a "could not be found" from the unit test project - Microsoft Q&A (8)

    Michael Taylor 52,721Reputation points

    2022-05-26T20:33:19.943+00:00

    However, that's because there is no .DLL located at

    That's a problem then. When you build your web app it should generate the DLL into the given folder. It is that reference that the unit test project is going to try to use. So the problem is that the web project isn't generating the output file.

    Let's start simple here. When you build you should see a summary that says Build: X succeeded. If you add up the succeeded and failed projects it should total the projects in your solution. So if you just have the web app + unit test then it should be 2. If that number is off then something has gone wrong. At that point I'd be jumping into Configuration Manager and making sure the solution build is configured to build all the projects and their platforms correctly.

    If everything is right there then we need to move to the build output. Go to Tools\Options -> Projects and Solutions\Build and Run. Change the MSBuiild project build log file verbosity to Detailed and then do a clean build. Within that huge log file you should see where it is building your web project and the output directory it is using. That's what we need to look at.

  9. Getting a "could not be found" from the unit test project - Microsoft Q&A (9)

    Rod At Work 866Reputation points

    2022-05-26T20:51:21.3+00:00

    When I do a build I see the following:

    Build: 0 succeeded, 2 failed, 0 up-to-date, 0 skipped

    Looking at Configuration Manager I see both projects have the Build checkbox, checked.

    I'm trying the detailed MSBuild project build log file verbodity option now. Where does it put that log file?

  10. Getting a "could not be found" from the unit test project - Microsoft Q&A (10)

    Rod At Work 866Reputation points

    2022-05-26T21:01:19.167+00:00

    FINALLY I found it! I was trying to find out where the log file was being written to. So, I scrolled up the Output window and saw that there was a warning (not an error) about a class not being found in a different view. I went to that view, removed the offending line, then tried to rebuild the app. It rebuilt fine and ran as well.

    Thank you, @Michael Taylor for your help!

Sign in to comment

Getting a "could not be found" from the unit test project - Microsoft Q&A (2024)

FAQs

How to add unit test project in .NET Core 6? ›

To create a unit test project

On the File menu, select New > Project, or press Ctrl+Shift+N. On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next.

Is unit testing done by developer or tester? ›

Unit testing is the first layer of the entire testing process software has to go through before its launch and release. This preliminary testing is often carried out by the team of developers or the software engineer that wrote the code for the software.

What is the meaning of unit testing in software testing? ›

Unit testing is the process where you test the smallest functional unit of code. Software testing helps ensure code quality, and it's an integral part of software development. It's a software development best practice to write software as small, functional units then write a unit test for each code unit.

Which is better, xUnit or NUnit? ›

Extensibility: NUnit: NUnit offers good extensibility through attributes, custom test runners, and extensions. XUnit: XUnit provides a higher level of extensibility through traits, custom attributes, and test case discovery extensibility.

Is unit testing hard? ›

Experience — Writing unit tests is one thing, but also creating your code to be testable in the first place can be quite a big learning curve, especially for new developers. Learning to write effective unit tests will take time and practice.

How do you structure a unit test project? ›

Arrange, Act, Assert is a common pattern when unit testing. As the name implies, it consists of three main actions: Arrange your objects, create and set them up as necessary. Act on an object.

How did you do unit testing in your project? ›

Effective unit testing typically:
  1. Runs each test case in an isolated manner, with “stubs” or “mocks” used to simulate external dependencies. ...
  2. Does not test every line of code, focusing on critical features of the unit under test. ...
  3. Verifies each test case using criteria determined in code, known as “assertions”.
Feb 14, 2024

What is unit testing vs QA testing? ›

While developers primarily write the unit tests, QA testers actively participate in the process to ensure comprehensive test coverage and maintain the overall quality of the codebase.

Who is mainly responsible for unit testing? ›

Unit testing is primarily the responsibility of developers.

However, in some organizations, there may be dedicated quality assurance (QA) teams or test engineers who assist with designing and executing unit tests.

Which tool is commonly used for unit testing in Java? ›

JUnit is a widely adopted testing framework for running Java unit tests. It provides annotations for test methods, supports assertions for result verification, and offers various runners for executing tests. JUnit is well-integrated with popular IDEs and build tools, making it a standard choice for developers.

What errors are commonly found during unit testing? ›

Unit testing considerations What errors are commonly found during Unit Testing? (1) Misunderstood or incorrect arithmetic precedence, (2) Mixed mode operations, (3) Incorrect initialization, (4) Precision inaccuracy, (5) Incorrect symbolic representation of an expression.

Who writes unit tests? ›

TDD (Test driven development) -unit tests are typically at a technical level. The developing unit should write them as they come to implement the class. The issue you may run into if others write the tests is that the external force will influence the design. TDD works well when the developers are doing the design.

What is the difference between unit testing and functional testing? ›

Functional testing ensures good accessibility, usability, and overall application experience, while unit testing helps maintain a robust codebase. By combining functional and unit testing, software development teams can ensure software quality and satisfy user expectations.

How to add unit testing to MVC project? ›

Add a new unit test project to the MVC module solution.
  1. In Visual Studio's Solution Explorer, right-click on your MVC module solution and select Add > New Project.
  2. In the Add New Project dialog, select Unit Test Project, enter a name, and select the local folder to store it in.

How to setup xUnit in C#? ›

Add xUnit NuGet Package: To use xUnit, we need to add the xUnit NuGet package to our project. Right-click on the project in the Solution Explorer, select “Manage NuGet Packages,” search for “xUnit,” and install the “xunit” package. Create a Test Class: In your project, add a new class for your tests.

How do I add unit test coverage to sonar? ›

General guidelines
  1. Set up your coverage tool to run as part of your build pipeline. ...
  2. Configure the coverage tool so that the location and format of the output report files match what the SonarScanner expects.
  3. Configure the analysis parameters of the SonarScanner so that it can import the report files.

What is unit testing in .NET Core? ›

Unit testing breaks the program down into the smallest bit of code, usually function-level, and ensures that the function returns the value one expects. By using a unit testing framework, the unit tests become a separate entity which can then run automated tests on the program as it is being built.

Top Articles
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 5489

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.