Skip to content
프로젝트

소개

Decorates stack traces with source code snippets.

기타 프로젝트

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
0
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Overview

Maven Central

The goal of this project is to decorate stack traces of test failures to make them more useful.

So instead of getting this when a test fails:

org.opentest4j.AssertionFailedError: expected: <hello> but was: <hi>
	at org.junit...
	at com.example.MyTest.hello(MyTest.java:24)
	...

You'll get this:

org.opentest4j.AssertionFailedError: expected: <hello> but was: <hi>
	at org.junit...
	at com.example.MyTest.hello(MyTest.java:24)

	   22    @Test
	   23    void compareStrings() {
	-> 24      assertEquals("hello", "hi");
	   25    }

	...

In both your IDE and build server test reports. Also works for other JVM languages.

Usage

Requires Java 11.

Gradle

dependencies {
  // For JUnit 5:
  testImplementation("nz.lae.stacksrc:stacksrc-junit5:${stacksrc.version}")
  // For JUnit 4:
  testImplementation("nz.lae.stacksrc:stacksrc-junit4:${stacksrc.version}")
  // For TestNG:
  testImplementation("nz.lae.stacksrc:stacksrc-testng:${stacksrc.version}")
}

Maven


<dependency>
  <groupId>nz.lae.stacksrc</groupId>
  <artifactId>stacksrc-junit5</artifactId> <!-- For JUnit 5 -->
  <artifactId>stacksrc-junit4</artifactId> <!-- For JUnit 4 -->
  <artifactId>stacksrc-testng</artifactId> <!-- For TestNG -->
  <version>${stacksrc.version}</version>
  <scope>test</scope>
</dependency>

JUnit 5

For JUnit 5, you can enable automatic extension detection by setting the system property junit.jupiter.extensions.autodetection.enabled=true on your build, then no other change will be needed for this to work.

If you don't want to enable automatic extension detection, you can wire things up manually using either JUnit's @ExtendWith or @RegisterExtension like the following, then all tests inheriting BaseTest will have their stack traces decorated on failure:


@ExtendWith(ErrorDecorator.class)
class BaseTest {
}

class MyTest extends BaseTest {
  @Test
  void myTest() {
    // ...
  }
}

JUnit 4

For JUnit 4, create a base test with a test rule, then all tests inheriting BaseTest will have their stack traces decorated on failure:

public class BaseTest {
  @Rule
  public final ErrorDecorator errorDecorator = new ErrorDecorator();
}

public final class MyTest extends BaseTest {
  @Test
  public void myTest() {
    // ...
  }
}

TestNG

No extra work is needed apart from adding the dependency.

관련 프로젝트 살펴보기

불러오는 중…