ASP.Net Core - Testing - Part 1.pdf - ASP.NET Core Testing...

This preview shows page 1 - 9 out of 59 pages.

ASP.NET Core Testing
Motivation Why running the application each time when you make changes in it? Why running the application each time when you introduce new functionality? Instead of having to manually run my app and test each scenario, we could press Play on a suite of tests and have the code tested for ourselves automatically. Testing is universally accepted as good practice, but how it fits into our development process can often turn into a religious debate.
Some simple questions on testing How many tests do you need? Is anything less than 100% coverage of your code base adequate? Should you write tests before, during, or after the main code?
Introduction to Testing Testing is a key part of developing any professional application Testing has traditionally been a manual, tedious and expensive process Agile development methodologies place even greater emphasis on testing than traditional approaches Agile development requires lots of repeat (regression) testing so the need for test automation is very high Visual Studio has extensive support for building and executing automated tests ASP.NET MVC and Web API were designed to be very testable hence follow Test Driven Development (TDD) Testing is very important for your Capstone Projects.
Test Triangle No of Tests Decreasing Scope of the Test Increase Cost of Individual Test Increases
Test Driven Development (TDD) An approach where tests are written before or at least in parallel with the actual code A major part of Agile Development Automated builds and automated tests are key parts of TDD and Continuous Integration strategies Visual Studio and ASP.NET Core MVC have excellent support for TDD. Typical sequence in TDD is: RED design a test that initially fails GREEN update the code under test just enough so that it passes REFACTOR refactor the code under test so that it is complete and rerun the test
Unit Tests Unit tests are the smallest sort of tests that you’ll write. Ideally, they exercise a single method and should be trivial to write. If you find unit tests difficult to write then it is an indication that the code being tested is doing too much and should be split up. Normally unit tests used as an indicator that methods should be split up into multiple methods or even split into separate classes. These are the sorts of tests you should create during test-driven development.
Unit Tests Conti… Unit testing tools are not new in .NET or in any modern language. The migration to .NET Core has brought with it most of the first-class unit testing tools. Unit testing tools are divided into a number of categories: Test frameworks Test runners Assertion libraries. The frameworks are a set of attributes that allow you to decorate your code such that they can be found and run.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture