Thursday, October 3, 2013

Method Stub

Stub :

Stubs are dummy modules which are known as "called programs" which is used in integration testing (top down approach), used when sub programs are under construction. A stub may simulate the behavior of existing code (such as a procedure on a remote machine) or be a temporary substitute for yet-to-be-developed code.
Example 1:
  
   BEGIN
       Temperature = ThermometerRead(Outside)
       IF Temperature > 40 THEN
            PRINT "It's HOT!"
       END IF
   END

BEGIN ThermometerRead(Source insideOrOutside)
        RETURN 28
   END ThermometerRead


Example 2: A drive program to calculate_income_taxfunction may consist line like
Cout << “income tax on 50000 is:”;
Cout << calculate_income_tax(5000)<<“\n”;

Example 3:
void function_under_test(int& x, int& y) {
  ...
  p = price(x);
  ...
}
double price(int x) {return 10.00;}
The value returned by function price is good enough for testing. The real price() function may not yet have been tested, or even written.


Driver:
Drivers are kind of dummy modules which are known as "calling programs", which is used in bottom up integration testing, used when main programs are under construction.
Example 1: to move a fighter on the game, the driver code would be 
moveFighter(Fighter, LocationX, LocationY);
This driver code would likely be called from the main method. A white-box test case would execute this driver line of code and check 
fighter.getPosition() to make sure the player is now on the expected cell on the board.

Example 2:           Edouble calculate_salary (double hours, double rate)
{      cout<< “salary is : ”;
                                   return (hours*rate);
                                 }
The main program can be tested using this code
Example 3:
#include <iostream.h>
void get_input(x& cost, int& y);
int main( )
{
    double a;
    int b;
    char ans;
    do
    {
        get_input(a, b);
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        cout << "a is " << a << endl;
        cout << "b is " << b << endl;
      
        cout << "Test again?"
             << " (Type y for yes or n for no): ";
        cin >> ans;
        cout << endl;
    } while (ans == 'y' || ans == 'Y');
    return 0;
}
Difference between stub and driver:

Stub
Driver

A piece of code that simulates the activity of missing component

A piece of code that passes test case to another piece of code

Stubs are created integration testing like Top-down approach 

Drivers are created integration testing like bottom-up approach

Stubs are simulations of the sub-code that otherwise is very gives full control to the test code

Driver takes care that the entry point of the application is masked by that of the test code and difficult to execute in the test code

A stub is a brief section of compliable code that serves as a class

A driver is a brief test program that demonstrates the functionality of a class or a portion of placeholder for future work

It is a temporary called program. It functions similarly like sub modules

It is a temporary Calling program. It functions similarly like main module for calling the sub when called by the main module

Stub is a simple routine that takes the place of the real routine Stubs let you check the interfaces and higher levels of the program

The driver approach is to write a program that passes input data to the unit under test and compares the output to the truth

Stub is a piece of special code that which is used to simulate the set up environment missing or not yet constructed

Driver is a code that which invokes the code to be tested

Stub is a skeleton of function having function header. This function can have actual statements or simple statements which can be      replaced with the actual code

Driver is a small program used to test a function

A driver creates necessary ‘Inputs’ required for      the Unit and then invokes the Unit

A driver creates necessary ‘Inputs’ required for the Unit and then invokes the Unit
Stub
Driver

Stubs can be "filled in" to form the actual method

Drivers can become automated test cases

Example: In module A and module B, module A      ready and module B is not. For integration testing of module A, a dummy module is created which stimulate like module B. This dummy module is Stub.

Example: module B cannot send or receive data from module A automatically so, in such case we have to transfer data from one module to another module by some external features. This      external feature used is called Driver.




References:
  1. Pressman, Roger S., Software Engineering: A Practitioner's Approach (P 459-462), New Delhi, 2011
  2. http://www.qualitytesting.info/forum/topics/difference-between-stubs-and
  3. http://www.cs.gmu.edu/~mcjunkin/cs112lectures/Stubs.htm
  4. http://forums.sureshkumar.net/testing-interview-technical-questions/13586-what-difference-between-stub-driver.html
  5. https://en.wikipedia.org/wiki/Method_stub

Adaptation and the Selection of Words


The Basic Need for Adaptation
          For writing to be clear, it must be adapted to the reader.

Visualizing the Reader
          Adaptation begins with visualizing the reader-imagining what he or she knows, feels, thinks, and such.

Technique of Adapting
          Often you will need to write at levels lower than your own.
          In writing to less-educated workers, for example, you may need to simplify. You may write differently for highly educated people.

Adapting to Multiple Readers
          Writing to multiple readers can be a challenge.
          Accommodating non experts usually does not impair your communication with experts.
          Write in the reader’s language, and don’t sacrifice effectiveness for brevity. 

Suggestion for Selecting Words
          Selecting the right words is a part of adaptation. Following are some suggestions to help you select such words.
          These suggestions stress simplicity for three reasons:
          (1) Many people tend to write at a difficult level.
           (2) the writer usually knows the subject better than the reader; and
          (3) The results of research support simplicity.

Use Familiar Words
          Familiar words communicate. Use them. Use your judgment in determining what words are familiar.
          Difficult words are not all bad. Use them when they fit your needs and understood.
          Unfamiliar words: This machine has a tendency to develop excessive and unpleasant audio symptoms when operating at elevated temperatures.
          Familiar words: This machine tends to get noisy when it runs hot.

Choose Short Words
          Generally, short words communicate better.
          Some exceptions exist.
          Generally, short words communicate better.
          Some exceptions exist.

Long Words:
          The decision was predicated on the assumption that an abundance of monetary funds was forthcoming.
          They acceded to the proposition to terminate business.

Short Words:
          The decision was based on the belief that there would be more money.
          They agreed to quit business.

Use Technical Words and Acronyms with Caution:
          All fields have technical words.
          These words are useful when you communicate with people in your field.
          Some examples are covered employment, cerebral vascular accident, annuity, and bobtail. These words are well known to people in special fields, but not to most outsiders.
          Use initials cautiously. Spell out and define as needed.
          Legal language has worked its way into business writing.
          Words like thereto, herewith, are examples.
          Replace legal language with plain words.

Use Concrete Language:
          Use concrete words.
          Concrete words are specific words.
          They stand for things that exist in the real world: deck, chair, road.
          Abstract nouns have general meanings: administration negotiation.
          Concreteness also means exactness: a 53 percent loss the odor of decaying fish. 



Abstract:
          A significant loss
          Good attendance record.

Concrete:
          A 53 percent loss
          100 percent attendance record

Use the active Voice
          Prefer the active voice to the passive voice.
          In active voice, the subject does the action. In passive voice, it receives the action.
          Active voice is stronger and shorter.

Passive:
          The results were reported in our July 9 letter.
          This policy has been supported by our union.

Active:
          We reported the results in our July 9 letter.
          Our union supports this policy.

Caution:
          Passive voice has a place. It is not incorrect.
          Passive is better when the doer of the action is not important.
          Passive helps avoid accusing the reader.
          Passive is better when the performer is not known.
          It is also better when the writer prefers not to name the performer.

Avoid Overuse of Camouflaged Words
          Avoid camouflaged verbs. You camouflage a verb by changing it to a noun form and then adding action words.
          For example, if cancel becomes cancellation, you must add “to effect a” to have action.


Action
Verb
                 Noun Form
Wording of Camouflaged
Verb
Acquire
Acquisition
Make an Acquisition
Appear
Appearance
Make an Appearance
Apply
Application
Make an Application


Camouflaged Verb:
          An arrangement was made to meet for breakfast.

Clear Verb Form:
          We arranged to meet for breakfast.

Avoid camouflaged verbs by
          (1) writing concretely and
          (2) Preferring active voice.

To comply with these suggestions
 (1) Make subjects persons or things
(2) Write sentences in normal order

Select Words for Precise Meanings
          Writing requires knowledge of language.
          You should study language and learn the shades of difference in the meanings of similar words.
          Select words with the right strength and vigor. Words have personalities. Select the stronger ones.
          Use correct idiom. Idiom is the way ideas are expressed in a language.


There is little reason to some idioms, but violations offend the reader.

Faulty Idiom:                     Correct Idiom:
Authority about                                Authority on
Comply to                           Comply with
Different than                   Different from

Suggestions for nondiscriminatory writing
          Avoid words that discriminate against sex, race, nationality, age, sexual orientation, or disability.
          We often use discriminatory words without bad intent.

Use Gender-Neutral Words

Masculine Pronouns for both sexes:
          Avoid using the masculine pronouns for (he, him, his) for both sexes.
You can do this
           (1) by rewording the sentence;
Sexist:
          If a customer pays promptly, he is placed on our preferred list.
Gender-Neutral:
          A customer who pays promptly is placed on our preferred list

 (2) By making the reference plural.

If customers pay promptly, they are placed on our preferred list.

          Or (3) by substituting neutral expressions.

If a customer pays promptly, he or she is placed on our preferred list.
          Neutral expressions can be awkward; so use them with caution.
               Avoid words suggesting male dominance, such as these examples;

Sexist:                  Gender-Neutral:
Man-made         Manufactured, of human origin
Manpower         Personnel, workers

          But not all man-sounding words are sexist.
Words that Lower Status by Gender:
          Do not use words that lower one’s status.
Avoid Words That Stereotype by Race, Nationality:
          Words depicting minorities in a stereotyped way are unfair and untrue.
          Words that present members of minorities as exceptions to stereotypes are also unfair
          Eliminate such references to minorities by treating all people equally and by being sensitive to the effects of your words.
Avoid Words that Typecast those with Disabilities
          Disabled people are sensitive to words that describe their disabilities.