Easily master vs code develop. Net Core and create Xunit unit tests

Source: Internet
Author: User
Tags dotnet xunit

Objective

This article is mainly about using vs code for. Net Core development and the use of common CLI commands, as to why use vs code, because it is really good-looking and useful:), haha, mainly for cross-platform development to prepare.

Development environment
    • Window 10
    • Install. NET Core and VS Code
    • C # for Visual Studio Code (powered by Omnisharp)
    • Vscode-nuget-package-manager
Common commands
    • Dotnet New Project (Solution, class library, unit test, etc.)
    • dotnet build builds the current project
    • Dotnet Run runs the current project
    • Dotnet sln Add adds a new project to the solution
    • dotnet Add Reference Adding a reference to a project
    • dotnet Test Execution Testing

For more information, refer to the official Microsoft Note:CLI command

Here's how:
  1. First we create a folder called Xunitdemo and open it with Vscode.

  2. Create a solution file, open the "Integrated terminal", the default path is the directory of the current file, enter dotnet new SLn and return, as shown in the Generate a sln file with the same name as the folder

  3. Create a new Class library project, in the current integration terminal, enter dotnet new Classlib-o demo.main,-o to specify the path to the output, as shown, creates a Demo.main folder and a. csproj file

  4. Next we create a Service.cs class file and include a simple method for easy testing, as shown in:

    CD demo.main switch to the Demo.main project path, execute the dotnet build Separate build new Demo.main class library,

    The resulting path is in "demo.main\bin\debug\netstandard2.0" because the default target framework uses. NET standard2.0, and if it is. Nerframework, a different folder is generated.
    Of course, we can also add multiple projects to the Xunitdemo solution, and finally build the solution.

  5. Create the unit test project as shown in the integrated terminal input: dotnet new Test-o demo.test

    Cd.. is to return to the parent directory, because we switched the path to the Demo.main folder.

  6. Add project to Solution in dotnet sln add demo.test\demo.test.csproj demo.main\demo.main.csproj
    Add Project reference Relationship,dotnet add demo.test\demo.test.csproj reference demo.main\demo.main.csproj

7. Write a simple test method and execute the test,dotnettest, as follows:

Conclusion

This article simply describes the simple process of using VS code to develop and use unit tests for. NET core, which is purely hand-crafted. On the one hand to find the feeling of writing articles, the first article of the year, the plan to write at least three blog posts per month;
Another convenience to pave the steps for subsequent. NET core articles.

Easily master vs code develop. Net Core and create Xunit unit tests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.