Http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE 517 Fall 2010/ch1 S10 MS

From Expertiza_Wiki
Revision as of 19:54, 21 September 2009 by Abhatt (talk | contribs) (→‎Ruby)
Jump to navigation Jump to search

Python

Doctest: It is a simple, ingenuine technology that allows you to write a narrative in a document which can directly be executed as a test. It is included in Python as a module. Although doctest makes testing code readable for non-programmers ,the simplicity of a narrative test like doctest is accompanied by it’s own flaws .Some of the disadvantages of using doctest are

• These tests are difficult to handle in case of failures as they are more generic. Specific tests are narrower and better in communicating intent and ensuring coverage.

• The test code is executed in a special way thus making it difficult to reason about how it will be executed. It is also harder to program around the tests.

• It is actually difficult to get an outline of the tests at glance. There’s no tool that can give an overview of the unit tests in a doc test file [2]

An detailed information about doctest with thorough examples can be read at http://docs.python.org/library/doctest.html


Unittest: Unittest are more specific tests which are more functional in nature allowing it to be written for individual functions or the class as a whole. The fact that Unittest is based on jUnit makes people with the xUnit familiarity pick it up really quick hence it is more Java based than python .It has been introduced in the Python’s library since version 2.1 The disadvantages of using the unit test are • The tests have a different look and feel with respect to the code under test

• The assertions used in the text use custom syntax which makes it difficult

• The test code is difficult to understand compared to the Doctest and the strong basis on jUnit makes it difficult for the pure Python coders [3]

A detailed information about doctest with thorough examples can be read at http://docs.python.org/library/unittest.html



Doctest vs Unittest

Here we compare simple features of both the tests thus giving us an idea of which one to use based on the requirement

' doctest unittest
Simplicity Best suited for novice programmers A little complex to use specially if unaware of Junit
Documentation Better Narratives Tests have little or no comments
Comprehensive testing Doctests get clutterd for comprehensive tests and thus less readable Best suited for comprehensive tests
Flexibility and Control Less flexible More flexible


Ruby

The basic testing framework for RUBY is xUnit . There are some frameworks which have evolved over the years which include RSpec, Trantula, Flog, RunCodeRun, Cucumber etc. We’ll talk about each of them in brief

Testing Framework '
Rspec[4] \"It is Behavior Driven Development whose basic features are
� Behavior counts first, testing follows
� It focuses more on business values
� It�s more about getting the words right rather than just writing the test first
Advantages:
� These are extremely easy to read and makes sense to a non-programmer
� Rspec lets you unit test while also providing mocking and stubbing support
� Rspec can help with the coverage tests using Rcov
� One can also perform integration test using Rspec
Disadvantages:
� It involves a lot of behind the scene metaprogramming which makes the tests very difficult to understand
A simple Rspec example can be read at http://rspec.info/
\"
Cucumber[5] \"Cucumber, the latest addition to the Rspec family allows one to execute documentation written in plain text(known as �stories�).
A very good example of writing a test in cucumber can be read at http://cukes.info/
\"
Tarantula[6] \"Tarantula is a Rail�s plugin that produces a detailed report describing the URL�s that it has crawled across and the responses that it received from each one of them.
Tarantula\'s functionality somewhat overlaps with the on site testing, particularly if you are practicing test-driven development (TDD). Tarantula runs against your actual Web site thereby helping you to identify the problems associated with your production server, user-generated data, and HTML compliance.
\"
Flog[7] \"Flog is a tool which gives you a profile of your code�s complexity. It can given the complexity pertaining to each method in your code. One can also set threshold for each method using flog
The complexity of a code can be important to
� Find the bugs as they are highly probable in complex code areas
� Complex codes can be considered for refactoring
A flog report has been explained and shown here http://www.ruby-forum.com/topic/131931
\"