简体   繁体   中英

Mockito avoid passing method arguments when calling Mockit.verify()

I want to test some method, for example:

      public class testObj {
        .. 
        public void upload(Context context, Data data, Info info, Listener listener, Bla bla, ....) {
          ...
        }

        }

now in some cases i just want to know that this method was called, but i do not care about anyy of the arguments passed.

Now calling Mockito.any(Foo.class) is very discouraging, I know i can also use matchers but it's not that great also.

Is there some cleaner way to achive this?

No; verify needs to identify the method you're referring to, which means you'll need to call the correct method signature. Keeping an actual method call will also allow IDEs and automated refactoring tools to search for and modify the calls appropriately.

If you're running your tests from a Java 8 source environment, you can use any() with no argument; Java 8 has improved the ability to infer generic types when given as a parameter.


Though it usually makes more sense just to use matchers and explicit calls, you do have a few similar capabilities:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM