dimanche 27 septembre 2015

Making a software test harness - combination of methods

I am building a software test harness in Java using the concept of reflection. The specification is that I will need to create test cases which have combination of methods.

For example, if you have the method int f(string) and the method float g(int) and the method string h(float), we would expect to test the combinations h(g(f("first value from a file"))), h(g(f(h(g(f"first value from a file")))))) and so on.

I have done it for a low level combination - f(h()); Can anyone help me with generating the next level combinations ?

Here's my code till now:

public static void LevelOne(Test testObject, Method[] method)
    {
        try{
        for(int i=0; i<method.length; i++)
        {
            for(int j=0; j< method.length; j++)
            {
                if( i!=j)
                {
                    Class[] parameterTypes = method[j].getParameterTypes();
                    Class returnType = method[i].getReturnType();
                    for( int k=0; k < parameterTypes.length; k++)
                    {
                        if(returnType.equals(parameterTypes[k]))
                        {
                            Class[] parameterFunction = method[i].getParameterTypes(); 
                            for(int l = 0; l < parameterFunction.length ; l++)
                            {
                                if(parameterFunction[l].equals(int.class))
                                {
                                    for(int num = 0; num <100; num++)
                                        method[j].invoke(testObject, method[i].invoke(testObject, num));
                                }

                                else if(parameterFunction[l].equals(String.class))
                                {
                                    method[j].invoke(testObject, method[i].invoke(testObject, "Hello World"));
                                }

                                else if(parameterFunction[l].equals(float.class))
                                {
                                    for(float num = 0.0f; num < 100.0f; num = num + 0.5f)
                                        method[j].invoke(testObject, method[i].invoke(testObject, num));
                                }

                                else;
                            }
                        }
                    }
                }
            }
        }
    } catch(Exception e)
        {

        }
    }

Aucun commentaire:

Enregistrer un commentaire