Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show method names in unit tests #156

Closed
tresf opened this issue Nov 19, 2023 · 0 comments · Fixed by #159
Closed

Show method names in unit tests #156

tresf opened this issue Nov 19, 2023 · 0 comments · Fixed by #159
Milestone

Comments

@tresf
Copy link

tresf commented Nov 19, 2023

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
@pietrygamat pietrygamat added this to the 2.9.6 milestone Dec 1, 2023
@tresf tresf closed this as completed in #159 Dec 9, 2023
tresf added a commit that referenced this issue Dec 9, 2023
* Shows method names for tests #156
* Removes slf4j from unit tests
* Fully switches to log4j for test logging
* Maven-like Log4j configuration for test execution
* Fixes Ubuntu pipeline

---------

Co-authored-by: Mateusz Pietryga <pietryga.m@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants