Sunday, December 1, 2013

Code Coverage in Testing

Primarily code coverage is used for unit testing and many test teams are practicising code coverage for test execution. Visual Studio team have been doing many improvements on code coverage area. Code coverage is available for Unit tests in prior version. In Visual Studio 2012 Update 3, Code coverage can be measured for manual and automated tests. Also there are few integrations with MTM (Microsoft Test Manager) tool.

Advantages of Code Coverage on Testing
  • Increase the confidence level on Quality
  • Measure the code coverage through tests
  • Help to improve testing to cover un-touched code
  • Additional test cases to increase code coverage


Limitations of Code Coverage on Testing
  • Unable to find incomplete or dead code
  • Not a proof whether code is written against specifications

You need to add your application DLLs into codecoverage.config file which is available at "C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools". Then use following commands in Administrator mode to get the coverage data. After stopping the code coverage, you can open the coverage results file in Visual Studio and expand the DLLs to method level.

Useful Commands
 
Path==> C:\Program Files (x86)\Microsoft Visual Studio 11.0\Team Tools\Dynamic Code Coverage Tools Command to run codecoverage tool ==> CodeCoverage.exe collect /IIS /session:WebSession /output:MyApp_20131009.coverage Command to stop codecoverage tool ==> CodeCoverage.exe shutdown /session:WebSession
Different attributes and options are available in code coverage tool. YOu can check your environment. CodeCoverage Help command
 
Usage: CodeCoverage Available Commands: Collect coverage data to the given coverage file. Usage: collect [options] [command line] Options: /config: [optional] Override default configuration with configuration file specified. /IIS [optional] Collect code coverage for web applications running under Internet Information Service (IIS). IIS Worker process (w3wp.exe) will be registered for collection and all the application pools will be restarted. /output: [required] The file to output coverage data to. /session: [optional] The name for the session. If a session name is not provided, a unique session name will be used /verbose [optional] Turn on printing of diagnostic information during runtime. Example: CodeCoverage collect /IIS /session:WebSession /output:MyWebApp.coverage Shut down a logger with a given session name. Usage: shutdown [options] Options: /session: [required] The name of the session to shut down Example: CodeCoverage shutdown /session:WebSession Analyze data from one or more coverage files and output XML. Usage: analyze [options] [file2 [...]] Options: /include_skipped_functions [optional] Includes skipped functions in the results. /include_skipped_modules [optional] Includes skipped modules in the results /output: [optional] The file to output the analyzed coverage data to The default is to use standard output /test: [optional] The test identifier string to limit the coverage data to. This option can be specified multiple times to merge coverage data for different tests together Example: CodeCoverage analyze /include_skipped_functions /include_skipped_modules /output:results.xml MyWebApp.coverage

5 comments:

Testleaf leaf said...

This is one awesome post.Thanks Again. Really Cool.

QTP Training in Chennai

Testleaf leaf said...

This is one awesome post.Thanks Again. Really Cool.

QTP Training in Chennai

Pushpak Pati said...

Can I register more than one session at a time in different command prompts for different executables ?

Akash Chauhan said...

This is a great info of software testing. Software Testing Jaipur

Cub Training said...

It was very nice article and it is very useful to Manual Testing learners.We also provide Cub training software online training.