zoukankan      html  css  js  c++  java
  • 近期准备学习的内容

    http://www.cnblogs.com/mecity/archive/2011/07/07/2099598.html

    EntityFramework之犹豫不决

    1).WorkFlow入门Step.1—My Frist WorkFlow Trip!

    http://www.cnblogs.com/hegezhou_hot/archive/2011/05/31/2064949.html

    2). http://www.cnblogs.com/gaizai/archive/2011/05/31/2064931.html

    SQL Server 表分区注意事项

    3).SqlServer2008 数据库同步的两种方式 (发布、订阅)

    http://www.cnblogs.com/tyb1222/archive/2011/05/31/2064944.html

    4).WorkFlow入门Step.1—My Frist WorkFlow Trip! (44/1359) »

    5)Visual Studio 2010 Tools - To improve code quality

    http://www.c-sharpcorner.com/UploadFile/sanks/1733/ 

    In this article, I am going to present a step by step demo on how to
    improve code quality by using Visual Studio Tools like:



    • Unit Testing: Writing piece of code to test another piece of code or
      functionality.
    • Code Coverage: This tells what lines of code getting executed during testing
      process.
    • Test Impact Analysis: This tells what test need to be run depending on under
      line code changes.

    Following tables shows features availability  in different Visual Studio
    2010 editions.

     

























    ProfessionalPremiumUltimate
    Unit TestingYesYesYes
    Code CoverageNoYesYes
    Test Impact AnalysisNoYesYes

    Step 1 : Create class library



    Class Library Name: MathLibrary

    Class Name: CalculateBasic

    Methods: AddNumbers, SubtractNumbers, MultiplyNumbers and DivideNumbers as
    shown below



    1.gif



    Step 2 : Create Unit Test



    Right any method and click "Create Unit Tests"



    2.gif


    Window will pop up. Select all methods and set Test Generation settings for
    file, class and method name. Click OK.



    3.gif


    Enter project name Unit Test project.



    4.gif


    New project created "MathUnitTest" with class CalculateBasicTest.cs having
    test methods for AddNumbersTest, SubtractNumbersTest, MultiplyNumbersTest and
    DivideNumbersTest as shown below. Remove Assert.Inconclusive statement from each
    method.



    5.gif


    Step 3 : Test Unit Test



    Click on Test Menu and select Run --> All Test in solutions.


    6.gif



    Here DivideNumbersTest fails because this unit test is trying divide by
    0.



    7.gif



    Change code to handle if 0 value is passed.



    8.gif



    Again click on Test Menu and select Run --> All Test in solutions. And
    now all tests are passed.



    9.gif



    Step 4: Enable Code Coverage and Test Impact Analysis



    To enable Code Coverage and Test Impact Analysis, click on Test --> Edit
    Test Settings --> Local (local.testsettings)



    10.gif



    Test settings windows pops up.



    1. Select Data and Diagnostics on left menu
    2. On Right side bottom screen, select Code Coverage and Test Impact
    3. Select Code Coverage and click Configure

    11.gif



    A new windows pops up. Select assemblies to be included for Code Coverage.
    Here   select both MathLibrary and MathUnitTest. Click OK.



    12.gif



    Step 5: Check Code Coverage



    Now again run all Unit Tests.



    13.gif


    All result is passed. Right click any test and select Code Coverage
    Results.



    13a.gif



    It shows code coverage in terms Not Covered and Covered lines by Unit
    Tests. Here Add, Subtract and Multiply method Covered Lines = 3 and Not Covered
    lines = 0. This shows that Unit Test covered all code. The Divide method Covered
    Lines = 4 and Not Covered lines = 2. This shows Unit Test has not covered 2
    lines of code. Right Click as show below and click Go to source code.



    14.gif


    The source code is divided in to two colors



    1. Code Covered 
    2. Code Not Covered

    15.gif



    Step 6: Test Impact Analysis



    The purpose of test impact analysis is to check the impact of any code on
    Unit Test.



    16.gif


    Change the Subtract and Multiply Numbers method to as shown below.



    17.gif



    For Test Impact Analysis, Click on Test --> Windows --> Test Impact
    View



    18.gif


    Build the solution and the Test Impact view window shows the list of
    impacted test.Here is shows Multiply and Subtract Numbers method as we have
    changed earlier.



    19.gif


    Right Click Unit Test and select Run All Impacted Tests.



    20.gif


    It shows both impacted test is passed.



    21.gif


    Again from here you can view the Code Coverage results.



    Conclusion:



    In this article I have tried to explain that by using Unit Testing, Code
    Coverage and Test Impact analysis how we can improve the quality of code.
    Analyzing these things helps during our code review process and also if there is
    any code change we can do the Test impact analysis.
    做个快乐的自己。
  • 相关阅读:
    tabbar 旋转指定的页面
    GDAL中文路径不能打开&Shp文件字段属性值中文乱码
    Project : error PRJ0019: 工具从"Moc'ing xxx.h..."
    详解Android中的屏幕方向
    qt中获取文件路径和文件名
    vs2005下Qt项目中修改exe图标的方法
    Qt & C/C++统计运行时间
    Qt 中Treewidget添加右键菜单
    QT 中文乱码解决方案
    Qt多线程应用QRunnable显示进度条示例
  • 原文地址:https://www.cnblogs.com/Jessy/p/2065422.html
Copyright © 2011-2022 走看看