Is it possible to have copilot use my own standards for how it writes unit tests?

Steven Bloomfield 20 Reputation points
2025-03-16T14:32:28.7233333+00:00

I find the most recent combo of VS2022 and copilot have gotten much better at writing unit tests. They have gone from doing 40-50% of the work to perhaps 80%, depending on the complexity of the class (I am using C#)

I use a prompt like "using mstest and moq, write unit tests for this class"

I then modify the results to do a few things the way I like to do them. For example, if the class is using IMapper from Automapper, copilot always mocks IMapper. But I have a factory method I use in tests to use the actual map profiles. So, instead of having:

private Mock<IMapper> _mockMapper;

..

_mockmapper = new Mock<Imapper>();

..

_mockmapper.Setup(blah blah)

I replace it with

private IMapper _mapper;

..

_mapper = MapFactory.Create();

..

Other than including something like "use MapFactory.Create() for IMapper" in the prompt, is there a way to change copilot to always use that in my projects?

Ultimately, I want to do this kind of thing for more than just the above IMapper example. But I don't know where to start. Was hoping there might be a "prompt rules" file I can include in a project with customizations like the above.

Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
367 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tianyu Sun-MSFT 34,311 Reputation points Microsoft External Staff
    2025-03-17T09:21:14.36+00:00

    Hi @Steven Bloomfield ,

    Good day!

    Please kindly check this document: Adding personal custom instructions for GitHub Copilot.

    It’s possible to add personal custom instructions for GitHub Copilot, but as the document says:

    Personal custom instructions are currently only supported for GitHub Copilot Chat in GitHub.

    However, adding repository custom instructions for GitHub Copilot is possible. I’m not sure if this can be another selection for you. You can also check this document: Enable custom instructions.

    Kind regards,

    Tianyu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.