MVC Unit-Testing
Upcoming SlideShare
Loading in...5
×
 

MVC Unit-Testing

on

  • 208 views

This presentation involves creating a new testing project for an ASP.NET MVC application and writing unit test methods.

This presentation involves creating a new testing project for an ASP.NET MVC application and writing unit test methods.

Statistics

Views

Total Views
208
Views on SlideShare
195
Embed Views
13

Actions

Likes
0
Downloads
2
Comments
0

2 Embeds 13

http://cms.revize.com 12
http://www.slideee.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    MVC Unit-Testing MVC Unit-Testing Presentation Transcript

    • MVC UNIT TESTING Presenter:Swati Gupta, Mindfire Solutions Date: 20/05/2014
    • Presenter: Swati Gupta, Mindfire Solutions I am Swati Gupta, working as a web developer with Mindfire Solutions .I am having 2 years and 9 months of core experience in web Development. I mostly work in .NET technologies like ASP.NET MVC 4.0/5.0, C#, Entity Framework, SQL Server 2008/2012, WCF and having proficient knowledge in MVC 4.0/MVC 5.0, CSS3, HTML5, jQuery, Twitter Bootstrap and Kendo UI for ASP.Net MVC. I am having three MS Certifications:  MCTS 70-515MCTS 70-515 (Web Development) Microsoft Certification ID: 9296947.  Microsoft exam 70-480Microsoft exam 70-480 (Programming in HTML5 with JavaScript and CSS3)  Microsoft exam 70-486Microsoft exam 70-486 Developing ASP.NET MVC 4 Web Applications.
    • Presenter: Swati Gupta, Mindfire Solutions AGENDA  Unit testing – What exactly it is and Why?  MVC and Unit Testing.  Create a new testing project for an ASP.NET MVC application.  Structure of a unit test class – Test Attributes.  Assert Class.  Mocking – what it is and why is it needed?  AAA approach.  Demo to explain how to create unit test methods.
    • UNIT TESTING What is a unit of source code?  Smallest part of a code that can be tested. In .NET languages, this is usually a method or a class. What is unit testing?  Process through which units of source code are tested.  Performing unit tests is a way to ensure that all functionalities of an application are working as they should. Unit Tests  Small, public and non static methods which are usually written in same language as SUT.  Make sure that bugs haven't been accidentally introduced into a codebase. Presenter: Swati Gupta, Mindfire Solutions
    • MVC AND UNIT TESTING  How ASP.NET MVC framework facilitates testing?  Major benefit of the MVC pattern is the separation of concerns that keeps User interface or Presentation logic away from application code. To have effective and clean unit test project:  Controller should act as a co-ordinator between views and model classes.  Translates user input [from the view] into object that can be used by our domain.  It shouldn't contain any business logic. Presenter: Swati Gupta, Mindfire Solutions
    • Presenter: Swati Gupta, Mindfire Solutions UNIT TESTING FRAMEWORKS Some examples of unit testing frameworks include:  CMSTest  xUnit  NUnit  MbUnit/Gallio  Mspec JS Testing frameworks:  Qunit  Jasmine  We will be using Microsoft Unit Testing Framework MSTest which is the default testing framework integrated with Visual Studio to explain how to write unit tests. Note: Its a part of Visual Studio not .NET framework.Its a part of Visual Studio not .NET framework.
    • CREATE YOUR FIRST TEST PROJECT Presenter: Swati Gupta, Mindfire Solutions
    • BASIC STRUCTURE OF A TEST CLASS Presenter: Swati Gupta, Mindfire Solutions
    • AAA APPROACH  All Unit Test methods should follow AAA. Presenter: Swati Gupta, Mindfire Solutions
    • METHODOLOGIES  Code First: write the code... then write the test method.  Test First [TDD]: Write the test... then write the code.  Behavior-Driven Development [BDD]: Based on TDD but it also addresses some of the issues that using TDD poses—where to start, what to test, how much to test in a cycle and what to call in the tests. BDD focuses on the behavioral requirements of the tested units. Presenter: Swati Gupta, Mindfire Solutions
    • CREATE UNIT TESTS  Demo to create simple unit test methods.  Run Unit tests and Debug.  Code Coverage – How to improve. Presenter: Swati Gupta, Mindfire Solutions
    • PROBLEMS WITH UNIT TESTS Presenter: Swati Gupta, Mindfire Solutions
    • MOCKING  Mocking is a process used in unit testing when the unit being tested has external dependencies.  To avoid hitting database.  Mocking is required when code that is coupled to other classes and accesses external resources.  Using a mock object in place of any kind of stateful dependency will isolate your unit test from external state and make your unit tests order independent and isolated.In mocking, the dependencies are replaced by closely controlled replacements objects that simulate the behavior of the real ones.  By isolating the dependencies, Mocking helps the unit testing process and aid developers in writing more focused and concise unit tests. The tests also perform faster by truly isolating the system under test. To demonstrate using EF with a mocking framework we are going to use Moq. Get Moq here http://nuget.org/packages/Moq/ via NuGet package or can download. Presenter: Swati Gupta, Mindfire Solutions
    • CREATE MOCK OBJECTS  Demo... Presenter: Swati Gupta, Mindfire Solutions
    • PROPERTIES OF A GOOD UNIT TEST  Atomic – Order independent.  Deterministic  Repeatable  Isolated  Should not block other unit tests.  Fast  Easy to set up. Presenter: Swati Gupta, Mindfire Solutions
    • BIT OF TDD Test-driven development is based on the test first methodology but with the introduction of refactoring. TDD has the following prescribed set of steps:  Write an automated unit test which will initially fail for the new functionality being implemented. Use mock objects to stand in for dependencies.  Write the minimum code needed to make the test pass. The code does not have to be perfect, it will be refined later.  Refactor (or clean up) the code or add additional user cases to the test  Ensure the tests still pass.  Repeat Presenter: Swati Gupta, Mindfire Solutions
    • Presenter: Swati Gupta, Mindfire Solutions Thank you
    • www.mindfiresolutions.com https://www.facebook.com/MindfireSolutions http://www.linkedin.com/company/mindfire-solutions http://twitter.com/mindfires