14

I am new to testing. I would like to know:

  • What is component testing?
  • How do I write component test cases?

Please explain with examples if possible to make it more helpful for me to understand.

2
  • You can find here a nice explanation about the Component testing.
    – Aguid
    Commented Dec 12, 2017 at 12:49
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – c32hedge
    Commented Dec 12, 2017 at 14:08

7 Answers 7

8

Component testing is testing of specific module or program.It may be done in isolation from rest of the system depending on the life cycle model selected for that particular application.

Stub and driver are used for competent testing. These both are consider as component.

Best example is given below :

Suppose you are testing one application which have 3 modules called X ,Y and Z. and think that each module is depends on above like Y is depends on X , Z is depends on Y. Now if developer developed Y module and as a tester if you want to test it then you need to use stub & driver as module X and Z.

Based on above example it will be easy to write test case for you.

0
4

What is Component testing?

  • Component testing is a method where testing of each component in an application is done separately.
  • Component testing is also known as module, unit or program testing. It finds the defects in the module and verifies the functioning of software.

For writing test cases for component testing I prefer making a checklist for all the components with a separate status and comment column to fill in the test results. You can also prepare detailed spreadsheet as explained by @jensi suthar but I prefer checklist because component testing may become very exhausting to manage with very detailed and lengthy documentation.


Dictionary Meanings: (Copied from Google Dictionary)

Unit: 1. an individual thing or person regarded as single and complete but which can also form an individual component of a larger or more complex whole. 2. a device that has a specified function, especially one forming part of a complex mechanism. synonyms: component, part, section, element, constituent, subdivision, portion, segment, module, item, member, ingredient, factor, feature, piece, fragment

Component: 1. a part or element of a larger whole, especially a part of a machine or vehicle. synonyms: part, piece, bit, constituent, element, ingredient; unit, module, item; section, portion

So as per the definitions given above, the terms can interchangeable depending on the context and individual's understanding.

5
  • I would argue that Unit testing is specifically not the same as component. A Unit is a deliberately small piece of code, whereas a component is composed of multiple units.
    – nullsteph
    Commented Oct 1, 2018 at 14:02
  • @nullsteph I've added the meanings and synonyms of the words Unit and Component to my answer. I hope that will give you more clarification on why Component and Unit Testing can be the same thing. Commented Oct 3, 2018 at 2:36
  • That's the generalized definition. Within the context of testing, it's usually considered separate. Check this out: watirmelon.blog/testing-pyramids
    – nullsteph
    Commented Oct 7, 2018 at 22:24
  • That's a nice article you've referred to. Although, the understanding of terminologies is always dependant on an individual or a team's perception. For example, in this case, Unit Testing and Component Testing are completely different things for you. Whereas, for me, they are interchangeable terms. So we (you and I) don't really have to agree to one thing/standard/rule as long as the stakeholders involved in the projects we are working on, get the point and desired result. Commented Oct 8, 2018 at 5:11
2

Component testing is a method where testing of each component in an application is done separately. Suppose, in an application there are 5 components. Testing of each 5 components separately and efficiently is called as component testing.

Let’s take an example to understand it in a better way.

Suppose there is an application consisting of three modules say, module A, module B and module C.

The developer has developed the module B and now wanted to test it. But in order to test the module B completely few of it’s functionalities are dependent on module A and few on module C. But the module A and module C has not been developed yet.

In that case to test the module B completely we can replace the module A and module C by stub and drivers as required.

Ref: component-testing

2

Component testing is that in which we test those test objects which are separately testable as a isolated unit without integrating with other components (e.g. modules, programs, objects, classes, etc.).

Testing of separate software component is known as component testing.

Component Testing is considered as the Module Testing, because we are testing each module or component differently and effectively.

Suppose there is only an one project which consists of 10 components and we are testing each component differently and effectively than it is known as component testing.

A group of component is known as module testing.

Component testing is fulfilled by programmers on the code written by them and with the support of development environment, such as a unit test structure or debugging tool.

Component Testing Example:

For Example there are two web pages. In one of the web pages there are a many certain fields like username, address, mobile no. etc in which data has to be entered. In the other (second) web page also there are certain fields which carry forward the data from the first page. Testing the functionality of these individual pages is called Component Testing.

You can write test case of component like as below snap format.

enter image description here

1

What is Component Testing?

Testing of separate software component is known as component testing.

Component Testing is considered as the Module Testing, because we are testing each module or component differently and effectively.

Suppose there is only a one project which consists of 10 components and we are testing each component differently and effectively than it is known as component testing.

Component testing is that in which we test those test objects which are separately testable as a isolated unit without integrating with other components (e.g. modules, programs, objects, classes, etc.). Component Testing Example

For Example there are two web pages. In one of the web pages there are a many certain fields like username, address, mobile no. etc in which data has to be entered. In the other (second) web page also there are certain fields which carry forward the data from the first page. Testing the functionality of these individual pages is called Component Testing.

After component Testing we always done the Integration Testing. While doing proper black box testing and white box testing by tester first of all Component Testing is done.

Before component Testing Unit Testing is always done by the developers. While doing proper Unit Testing the Developers run each functions and method of the Component effectively.

0

Testing of separate software component is known as component testing.

Component testing means testing of single part of software/Website. This can be program module , single function etc.

For example if you have website which has 2 page registration process. Now assume that 2nd page data is depend on 1st page data , and if developed has done code for only 1st page then tester can test only 1st page so this is called one component testing.

0

Component testing is a method where testing of each component in an application is done separately. Component testing is also known as module, unit or program testing. It finds the defects in the module and verifies the functioning of software.

Before I jump to brief about Stubs and Drivers, I should brief about the difference between Component tests and Integration tests. The reason is – Stubs and drivers are also used in Integration testing so this may lead to some confusion between these two testing techniques.

Integration testing technique is a technique where we combine 2 components sequentially and test the integrated system together. Data from one system is traversed to another system and the correctness of data is validated for the integrated system.

Unlike module testing where the single component/module is tested thoroughly before integrating it to other components. So we can say that Component testing is performed before Integration testing.

Both Integration and Component uses Stubs and Drivers.

“Drivers” are the dummy programs which are used to call the functions of the lowest module in case the calling function does not exist.

“Stubs” can be referred to as code a snippet which accepts the inputs/requests from the top module and returns the results/ response

As explained earlier, the components are tested individually and independently. So there may be some features of the components, dependent on the other component which is not developed currently. So in order to test the components with these “undeveloped” features, we have to use some stimulating agents which would process the data and return it to the calling components.

Examples:

We now consider an example in which we need to develop a "calculator" that converts between different units (e.g., feet to inches). We start by "stubbing-out" the Unit Converter class. This "stubbed-out" class contains comments that describe the class and all of the methods that we expect it to have (appropriately commented). All of the non-void methods return an appropriate default so that the class can be compiled.

/** * Converts from one unit to another (e.g., inches to feet) * * @author Prof. David Bernstein, James Madison University * @version 0.1 (Stub) */ public class UnitConverter {

/**
 * Default Constructor
 */
public UnitConverter()
{

}


/**
 * Perform a conversion
 *
 * @param value    The number to convert
 * @param from     The units for value (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         The converted value
 */
public double convert(double value, String from, String to)
{


    return 0.0;
}



/**
 * Get the multiplier needed for a conversion
 *
 * @param from     The units to convert from (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         What "from" needs to be multiplied by to get "to"
 */
public double getMultiplier(String from, String to)
{

    return 0.0;
}

}

Note that these two classes can be compiled and executed.

The next version of the Unit Converter contains a complete implementation of the convert method but still contains a stub of the getMultiplier method (which has been changed slightly to make it more useful). This enables us to test the convert method (using the driver) independently from the other methods.

/** * Converts from one unit to another (e.g., inches to feet) * * @author Prof. David Bernstein, James Madison University * @version 0.2 (Implemented convert) */ public class UnitConverter {

/**
 * Default Constructor
 */
public UnitConverter()
{

}


/**
 * Perform a conversion
 *
 * @param value    The number to convert
 * @param from     The units for value (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         The converted value
 */
public double convert(double value, String from, String to)
{
    double     result;

    result = value * getMultiplier(from, to);
    return result;
}



/**
 * Get the multiplier needed for a conversion
 *
 * @param from     The units to convert from (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         What "from" needs to be multiplied by to get "to"
 */
public double getMultiplier(String from, String to)
{

    return 1.0 / 12.0;
}

}

The next version of the UnitConverter contains an implementation (though not a very good one) of the getMultiplier method.

/** * Converts from one unit to another (e.g., inches to feet) * * @author Prof. David Bernstein, James Madison University * @version 1.0 (Implemented getMultiplier) */ public class UnitConverter {

/**
 * Default Constructor
 */
public UnitConverter()
{
}


/**
 * Perform a conversion
 *
 * @param value    The number to convert
 * @param from     The units for value (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         The converted value
 */
public double convert(double value, String from, String to)
{
    double     result;

    result = value * getMultiplier(from, to);
    return result;
}



/**
 * Get the multiplier needed for a conversion
 *
 * @param from     The units to convert from (e.g., "inches")
 * @param to       The units to convert to (e.g., "feet")
 * @return         What "from" needs to be multiplied by to get "to"
 */
public double getMultiplier(String from, String to)
{
    double        multiplier;

    multiplier = 1.0;
    if        (from.equals("inches")) {

        if      (to.equals("feet"))   multiplier = 1.0/12.0;
        else if (to.equals("yards"))  multiplier = 1.0/12.0/3.0;
        else if (to.equals("miles"))  multiplier = 1.0/12.0/3.0/1760.0;

    } else if (from.equals("feet")) {

        if      (to.equals("inches")) multiplier = 12.0;
        else if (to.equals("yards"))  multiplier = 1.0/3.0;
        else if (to.equals("miles"))  multiplier = 1.0/3.0/1760.0;

    } else if (from.equals("yards")) {

        if      (to.equals("inches")) multiplier = 3.0*12.0;
        else if (to.equals("feet"))   multiplier = 3.0;
        else if (to.equals("miles"))  multiplier = 1.0/1760.0;

    } else if (from.equals("miles")) {

        if      (to.equals("inches")) multiplier = 12.0*3.0*1760.0;
        else if (to.equals("yards"))  multiplier = 1760.0;
        else if (to.equals("feet"))   multiplier = 3.0*1760.0;
    }

    return multiplier;
}

To test this version of the UnitConverter we need to modify the driver so that it generates more test cases. In this case we use "white-box (or glass-box) testing" (i.e., we look at the UnitConverter class to identify important test cases) and write a driver that tests all supported inputs.

/** * A driver for testing the UnitConverter class * * @author Prof. David Bernstein, James Madison University * @version 2.0 */ public class Driver { /** * The entry point of the application * * @param args The command-line arguments */ public static void main(String[] args) { double converted, original; int i, j; String from, to; String[] units = {"inches","feet","yards","miles"}; UnitConverter calculator;

    calculator = new UnitConverter();

    original  = 10.0;

    for (i=0; i < units.length; i++) {
        for (j=0; j < units.length; j++) {

            from      = units[i]; // This could be outside the inner loop
            to        = units[j];
            converted = calculator.convert(original, from, to);
            System.out.println(original+" "+from+" = "+converted+" "+to);
        }
    }
}

}

This process continues until a satisfactory version of the UnitConverter is completed.

Rick Bradford, Sr. Mobility Automation Test Engineer, Bradteli-MSI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.