Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ public class LoginTests {

### Behavior

- **Tests without `@TestId`**: Included when no filter is applied; skipped when `-Dids` is provided (TestNG only)
- **Tests without `@TestId`**: Included when no filter is applied; skipped when `-Dids` is provided
- **Tests with matching IDs**: Always run when their ID is in the filter list
- **Tests with non-matching IDs**: Skipped

Expand Down
2 changes: 1 addition & 1 deletion java-reporter-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
<packaging>jar</packaging>

<name>Testomat.io Reporter Core</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.testomat.core.constants;

public class CommonConstants {
public static final String REPORTER_VERSION = "0.10.0";
public static final String REPORTER_VERSION = "0.10.1";

public static final String TESTS_STRING = "tests";
public static final String API_KEY_STRING = "api_key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import io.testomat.core.step.StepStatus;
import io.testomat.core.step.StepTimer;
import io.testomat.core.step.TestStep;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -80,12 +81,12 @@ public static void step(String stepName, Runnable action) {
step.setStatus(StepStatus.passed);
} catch (Throwable t) {
step.setStatus(StepStatus.failed);
step.setLog(Arrays.toString(t.getStackTrace()));
step.setLog(getStackTrace(t));
step.setError(
Optional.ofNullable(t.getMessage())
.orElse(t.getClass().getSimpleName())
);
throw new RuntimeException(t);
throwUnchecked(t);
} finally {
durationMillis = StepTimer.stop(step.getId().toString());
step.setDuration(durationMillis);
Expand Down Expand Up @@ -123,4 +124,20 @@ public static void label(String labelName, List<String> labelValues) {
}
}
}

private static String getStackTrace(Throwable t) {
StringWriter sw = new StringWriter();
t.printStackTrace(new PrintWriter(sw));
return sw.toString();
}

private static void throwUnchecked(Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
}
if (t instanceof Error) {
throw (Error) t;
}
throw new RuntimeException(t);
}
}
2 changes: 1 addition & 1 deletion java-reporter-cucumber/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-junit</artifactId>
<version>0.8.3</version>
<version>0.8.4</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter JUnit</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import io.testomat.core.annotation.TestId;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.platform.engine.FilterResult;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.engine.TestSource;
import org.junit.platform.engine.support.descriptor.MethodSource;
import org.junit.platform.launcher.PostDiscoveryFilter;

public class TestIdFilter implements PostDiscoveryFilter {
Expand Down Expand Up @@ -34,31 +36,35 @@ public FilterResult apply(TestDescriptor testDescriptor) {
return FilterResult.included("No ids filter specified");
}

if (testDescriptor instanceof TestMethodTestDescriptor) {
TestMethodTestDescriptor methodDescriptor = (TestMethodTestDescriptor) testDescriptor;
Method testMethod = methodDescriptor.getTestMethod();
Optional<TestSource> optionalTestSource = testDescriptor.getSource();

TestId testIdAnnotation = testMethod.getAnnotation(TestId.class);
if (optionalTestSource.isEmpty()) {
return FilterResult.included("No source specified");
}

if (testIdAnnotation != null) {
return getFilterResult(testIdAnnotation);
} else {
return FilterResult.included(
"Test method without @TestId annotation is allowed when filtering by IDs");
}
TestSource source = optionalTestSource.get();

if (!(source instanceof MethodSource)) {
return FilterResult.included("No method source specified");
}

return FilterResult.included("Not a test method");
return resolve((MethodSource) source);
}

private FilterResult getFilterResult(TestId testIdAnnotation) {
String testId = testIdAnnotation.value();
boolean isAllowed = allowedIds.contains(testId);
private FilterResult resolve(MethodSource methodSource) {
Method method = methodSource.getJavaMethod();
if (method == null) {
return FilterResult.included("No Java method specified");
}

if (isAllowed) {
return FilterResult.included("Test ID " + testId + " is in allowed list");
} else {
return FilterResult.excluded("Test ID " + testId + " is not in allowed list");
TestId testId = method.getAnnotation(TestId.class);

if (testId == null) {
return FilterResult.excluded("No TestId annotation found");
}

return allowedIds.contains(testId.value())
? FilterResult.included("Allowed " + testId.value())
: FilterResult.excluded("Not allowed " + testId.value());
}
}
Loading
Loading