How to test whether a method has been overriden in junit?

眉间皱痕 提交于 2019-12-05 17:58:01

you could do it like this probably:

 class.getMethod("toString").getDeclaringClass();

Here is a sample:

  class Test {
         public String toString(){
              return "From test";
         }
  }

  public static void main(String[] args) throws NoSuchMethodException, SecurityException {
    String resut = Test.class.getMethod("toString").getDeclaringClass().getName();
    System.out.println(resut);
}

Now run this with toString firs overridden then comment it out and you will see the output and "Test" then "Object"

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!