To add xUnit test to the solution add a Class Library (Package) project.
![image image](https://lh3.googleusercontent.com/-GiI1F4wwwBg/VtQjORD-uNI/AAAAAAAAG5k/jQ5O-cVwLUA/image_thumb%25255B3%25255D.png?imgmax=800)
![image image](https://lh3.googleusercontent.com/-D3ChPiSphtY/VtQjSbPVHRI/AAAAAAAAG5s/yzK-EU0yF8Y/image_thumb%25255B4%25255D.png?imgmax=800)
Edit the default project.json shown below.
![image image](https://lh3.googleusercontent.com/-DtA3f4VmbdQ/VtQjXh-oYhI/AAAAAAAAG50/2l79lw5lGXU/image_thumb%25255B5%25255D.png?imgmax=800)
Add dependency to the ASP.Net 5 web project, and to xUnit and xUnit.Runner.Final project.json should be similar to below.
![image image](https://lh3.googleusercontent.com/-fPIABoseZ-I/VtQjb5S3dwI/AAAAAAAAG58/iOeYR9j8Tjg/image_thumb%25255B6%25255D.png?imgmax=800)
{ "version": "1.0.0-*", "description": "BookMyEvents.UnitTests Class Library", "authors": [ "Chaminda" ], "tags": [ "" ], "projectUrl": "", "licenseUrl": "", "dependencies": { "BookMyEvents": "1.0.0-*", "xunit": "2.1.0", "xunit.runner.dnx": "2.1.0-rc1-build204" }, "commands": { "test": "xunit.runner.dnx" }, "frameworks": { "dnx451": { }, "dnxcore50": {} } }
![image image](https://lh3.googleusercontent.com/-JUzYG7YgU_s/VtQjfxF5CtI/AAAAAAAAG6E/NaAAOVRNinE/image_thumb%25255B2%25255D.png?imgmax=800)
Let’s write a test for a very simple controller method.
![image image](https://lh3.googleusercontent.com/-tWxKG7pOfs8/VtQji9R53GI/AAAAAAAAG6M/mV_wlSLmvv4/image_thumb%25255B12%25255D.png?imgmax=800)
Test method as a Fact (There are two types of Unit Tests in xUnit. Fact and Theory. More information here).
![image image](https://lh3.googleusercontent.com/-gHL3yJvdBzY/VtQjoq0AoeI/AAAAAAAAG6U/kKegc9WtL6k/image_thumb%25255B13%25255D.png?imgmax=800)
Go to test explorer in VS to view the test.
![image image](https://lh3.googleusercontent.com/-sfHyyPn0tfM/VtQjtFutHBI/AAAAAAAAG6c/39HFNLtNG88/image_thumb%25255B15%25255D.png?imgmax=800)
![image image](https://lh3.googleusercontent.com/-CnHKBgI9dLw/VtQjxJVAzXI/AAAAAAAAG6k/uicaKtcp9eI/image_thumb%25255B16%25255D.png?imgmax=800)
If you cannot see test as above build your solution. Test will be then available in the explorer. Execute and you can see the results.
![image image](https://lh3.googleusercontent.com/-T2GifMbVXrQ/VtQj08MV_4I/AAAAAAAAG6w/BoL5s3ABAEA/image_thumb%25255B18%25255D.png?imgmax=800)
Next post let’s learn how to run the unit tests (xUnit), with VS Team Service build and publish test results.
1 comment:
Hello,
The Article on Unit Test for ASP.Net 5 with xUnit is very informative. It give detail information about it .Thanks for Sharing the information on Unit testing for ASP.net.
Software Testing Services
Post a Comment