0

I need to get a report from my unit test. I found and used JMockit plugin to mock different environments which were required for tests. But I found that I can't get the coverage report when I mock static methods. The mock tests all ran successfully. See the report screenshot below:

Coverage Result Coverage Code Line

So is there any problem in my code? Maybe somebody who has better experience with JMockit can you help me with this. Thanks.

You can get the code from here:

  1. Maven Pom File
  2. Static Source Code
  3. Test Code
TheEllis
  • 1,666
  • 11
  • 18
elkan1788
  • 97
  • 1
  • 2
  • 11
  • Another reason to avoid using static methods -- they make your code difficult to test. – Hovercraft Full Of Eels Jul 03 '16 at 15:43
  • Maybe this answer might help: http://stackoverflow.com/questions/26408253/how-to-mock-a-static-method-from-jmockit – Heri Jul 03 '16 at 18:04
  • Looking at the tests in `HttpToolTest`, they all seem rather pointless to me, as each test simply checks that JMockit itself is working... – Rogério Jul 04 '16 at 22:01
  • Or, to put @Rogério's comment another way ... if you are testing a method, ***do not mock that method***. When a method is mocked, flow of control never enters that method and you won't actually test (or get coverage for) that method. You should be mocking the objects that `HttpTool` uses, not `HttpTool` itself. – dcsohl Jul 05 '16 at 14:27
  • @dcsohl Thanks for you reply. Actually I also had a class reference the HttpTool, but the coverage not show up in report. – elkan1788 Jul 06 '16 at 14:29
  • Perhaps you would be so bold as to include that information in your question? Better yet, a [small complete project that replicates your problem](http://stackoverflow.com/help/mcve), so somebody else can take a look? – dcsohl Jul 06 '16 at 14:32
  • @dcsohl yeah, Now I had build a simple project, can you take a look? thanks. --> https://github.com/elkan1788/jmockit-study – elkan1788 Jul 07 '16 at 05:49

0 Answers0