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));

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

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"))
                  Method cE = kunit.getClass().getDeclaredMethod(m.getName(), double.class, double.class);


I am stuck after that. Can someone help me?


Recommended Answers

All 3 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.