Hello,

I am trying to build a basic unit framework. I have got this method in a class called KUnit3

public static void checkEquals(double value1,double value2) {

    if(value1 == value2) {
        addToReport(String.format(" %f == %f", value1, value2));
        passedChecks++;

    } else {
        addToReport(String.format("* %f == %f", value1, value2));
        failedChecks++;
      }
}

I have to access this method using Java reflection API from a class called 'TestASimpleClass' like for example

checkEquals(double value1, double value2)

Below is what I have done so far

    public static void main(String[] args) throws Exception{
    KunitTesting kunit = new KunitTesting();
        ASimpleClass simple = new ASimpleClass();
        Method [] method = kunit.getClass().getMethods();

        for (Method m : method) {
            if( m.getName().startsWith("check"))
               {
                  m.setAccessible(true);
                  Method cE = kunit.getClass().getDeclaredMethod(m.getName(), double.class, double.class);
                  System.out.println(cE);


               }
        }

I am stuck after that. Can someone help me?

Thanks

Which is the method object? is it the method?
if method is the object, would it be this

cE.invoke(method, 40.02, 40.02);

How do I use the checkEquals method from the 'Kunit3' class/

Thanks for the help. I am really stuck

Edited 1 Year Ago by Mohamed_26

This article has been dead for over six months. Start a new discussion instead.