-3

Power mock framework doing the same thing which i can do by reflection .

And test driven environment can be achieve by both for Spring based container.

Santosh
  • 111
  • 2
  • 10
  • 1
    Powermockito _can_ access private methods. You can achieve a lot of what powermockito does with reflection (especially if you're just accessing a private method), but power mockito makes it a _lot_ easier. – BeUndead Jul 16 '19 at 15:51
  • I can get the necessary data output by reflection And if i want to do the same thing then i can use the Reflection Util introduce by spring framework.. But what extra thing power mock can do can you elaborate more. – Santosh Jul 16 '19 at 16:03
  • 1
    Firstly, you can mock interfaces (yes, you can do this with proxying and reflection, but it's hard). You can mock static methods (I have no idea how I'd do this via reflection, possibly impossible). You can mock what happens when `new *` is called (again, possibly impossible with reflection). – BeUndead Jul 16 '19 at 16:12
  • I can access the static method by reflection as well it's possible – Santosh Jul 17 '19 at 08:17
  • I didn't say access, I said _mock_. I.e. change what the result of _calling_ that method would be if a class which you were testing invokes it part way through. This can be useful for artificially creating errors (having the method throw an `IOException` without having to break your filesystem, for example) amongst other things. – BeUndead Jul 17 '19 at 08:37
  • I think you need some practice for the mock. – Santosh Jul 17 '19 at 16:52

1 Answers1

1

I guess most things in Java can be done using reflection. You could implement your own collection classes using reflection, if you wanted. Mocking libraries allow you to easily, without a ton of boilerplate code:

  • Create mocks
  • Create spies
  • Stub out methods
  • Overwrite methods with your own test functionality
  • Match arguments up with method calls
  • Check which methods were called and how many times in a given execution

PowerMock specifically also allows you to

  • Mock static methods
  • Mock constructors
  • Mock final classes
  • etc

But a mocking library itself is just java code and you could always do this stuff yourself if you want to rewrite something similar using reflection.

user506069
  • 771
  • 1
  • 6
  • 14