Skip to content

Show method names in unit tests #156

@tresf

Description

@tresf

I'm not sure why this isn't the default behavior -- or at a minimum, a configured behavior -- but JUnit hides the method names from the unit tests. This makes it hard to know which particular test is failing a build (or in the event of #155, which test is hanging the build).

I'm not very seasoned with JUnit, so there's probably a better way to do this, but using a boilerplate class, we can add this rule to each test we run.

package jssc.junit.rules;

import org.junit.Rule;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

public class ShowMethodNames {
    @Rule
    public TestRule watcher = new TestWatcher() {
        @Override
        protected void starting(Description description) {
            String line = "-------------------------------------------------------";
            System.out.println(String.format("\n%s\n METHOD: %s\n%s", line, description.getMethodName(), line));
        }
    };
}
- public class SerialNativeInterfaceTest  {
+ public class SerialNativeInterfaceTest extends ShowMethodNames {
...

Resulting in the following:

  [INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.662 s - in jssc.VirtualPortTest
  [INFO] Running jssc.SerialNativeInterfaceTest
+
+ -------------------------------------------------------
+ METHOD: testInitNativeInterface
+ -------------------------------------------------------
  12:52:09.858 [main] DEBUG org.scijava.nativelib.BaseJniExtractor - Not deleting leftover folder 
  /var/folders/mp/xz8fb9m55f9g8vb7fs9gc3140000gn/T/nativelib-loader_15778748976254708994: is 0ms old

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions