Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

2. Go to the bin directory, for example:

cd opt/-*/binbinH

3. Run idea.sh from the bin subdirectory.

...

Compiling

coming soon

Unit Testing

In this tutorial, we recommend to use Junit4 and Mockito for writing the junit test.

Add dependency

Add Junit and mockito dependency in the pom.xml if they are not there.

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

For more information about how to use Mockito, refer to https://www.tutorialspoint.com/mockito/.

Mock class level attributes

Since we don't recommend to use Powermockito, however, if sometimes you do want to set/get class level attributes to satisfy complex test code and still keep the test coverage in sonar achievable.

WhiteBox is the class under package org.mockito.internal.util.reflectio that could be used to do code reflection.

static ObjectgetInternalState(Object target, String field) 
static voidsetInternalState(Object target, String field, Object value) 

Issue of using Powermockito

There are multiple advantages of using Powermock to easily write the junit test, but it does break the design of the code and even sometimes, the written Junit doesn't contain any real test value.

Another reason is that there is compatibility issue between PowerMock and Jacoco which leads to the 0% test coverage in sonar.

The issues is that Jacoco does not like PowerMock instrumentation. Here is a detail explanation: https://github.com/powermock/powermock/wiki/Code-coverage-with-JaCoCo


Reference link:

https://static.javadoc.io/org.mockito/mockito-core/2.0.10-beta/org/mockito/internal/util/reflection/Whitebox.htmlcoming soon

How to Commit Code

Install git-review

...