For a class named Foo:
public class Foo
{
public static int add(int x, int y) { return x+y; }
}
write a JUnit test like this:
public class FooTest:
{
@Test
public void testAdd()
{
int expected = 5;
int actual = Foo.add(2, 3);
Assert.assertEquals(expected, actual);
}
}
I create /src and /test folders in my IntelliJ project and mirror the package structure under each one.
You can have IntelliJ run all the tests in your project by right clicking on the /test folder and selecting "Run all tests".
If you edit configurations on your "all tests" task, you'll see a checkbox to ask IntelliJ to check code coverage for you. It'll refresh the values after every test run.