0

native init method I mean it is a field in a class init by a native method. This is my code.

class Operator {
    private sr = new SR();
    ...
}

class SR {
    public SR() {
        aNative.new_instance(); // where the native method is called
    }
}

when I mock the Operator, it will throw an exception: Underlying exception : java.lang.IllegalArgumentException: Could not create type

My java version is 8. the mockito-inline version is 3.9.0. the bytebuddy version is 1.10.20. I used to change the java version to 11 but it does not work.

I can mock other classes without a native init method.

S.Lee
  • 206
  • 1
  • 4
  • 15

1 Answers1

2

Mockito does not support mocking native methods: Mockito - mocking classes with native methods

One option would be Powermock.

wrf
  • 56
  • 4