简体   繁体   中英

Unit Testing of Class Library (Package) .Net 4.6

I successfully moved my code to the new Class Library (Package) project type, all code build and compile. From what I can gather it is not possible to add a project reference anymore

在此输入图像描述

I could however set the Produce outputs on build setting that created a dll in the artifacts\\bin folder that I could reference from my Unit Test project. The problem that I'm experiencing now is that I can't step into the code from the referenced dll when debugging my Unit Test, there is a .pdb file within the folder I'm referencing from but I just can't seem to step through my code.Is there anything I'm missing?

Microsoft unit testing is a really different thing than unit testing a package application. I recommend you to use xUnit. xUnit is both cross platform and easy to use.

check here

How to (The difficult way):

1) Create a package application(with your main project to be tested)

2) Check your dnx version from your global.json file in your project(ex: mine is 1.0.0-beta5)

3) Look at the link that i sent you, there is a green table that shows you which versions are supported with the dnx versions.

So in my case: my supported xunit package version is 2.1.0-beta3-build3029 and runner version is 2.1.0-beta3-build99

4) Open up your project.json file(test project) and add the packages(according to the documentation that i sent you.)

    "dependencies": {
    "xunit": "2.1.0-beta3-build3029",
    "xunit.runner.dnx": "2.1.0-beta3-build99"
  },

and

    "commands": {
    "test": "xunit.runner.dnx"
  },

and thats all. It must be working now. You can find the documentation in xunit github page(its a little bit different than MStest).

How to (The easy way / This may not work due to the version confliction mentioned above. Visual studio will always get the latest version, while latest version might not be the one that suites your dnx version):

  1. Browse to the Tools/Extensions and Updates... menu in visual studio
  2. Install the xUnit Test Project Template extension
  3. Install the xUnit.net Test Extension
  4. Create a new xUnit Test project
  5. Write some tests

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM