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 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.19.0</version>
<version>0.19.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.19.0";
public static final String REPORTER_VERSION = "0.19.1";

public static final String TESTS_STRING = "tests";
public static final String API_KEY_STRING = "api_key";
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-cucumber/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-cucumber</artifactId>
<version>0.10.0</version>
<version>0.10.1</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter Cucumber</name>
Expand Down Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.19.0</version>
<version>0.19.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.10.0</version>
<version>0.10.1</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.19.0</version>
<version>0.19.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-karate/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-karate</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter Karate</name>
Expand Down Expand Up @@ -52,7 +52,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.19.0</version>
<version>0.19.1</version>
</dependency>
<dependency>
<groupId>io.karatelabs</groupId>
Expand Down
4 changes: 2 additions & 2 deletions java-reporter-testng/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-testng</artifactId>
<version>0.9.0</version>
<version>0.9.1</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter TestNG</name>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.19.0</version>
<version>0.19.1</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ public class TestNgParameterExtractor {
*/
public Object extractExample(ITestResult testResult) {
Object[] parameters = testResult.getParameters();
Map<String, Object> exampleMap = new HashMap<>();

if (parameters == null || parameters.length == 0) {
return null;
}

if (parameters.length == 1) {
return parameters[0];
exampleMap.put("param0", parameters[0]);
return exampleMap;
}

Method method = testResult.getMethod().getConstructorOrMethod().getMethod();
String[] parameterNames = extractParameterNames(method, parameters.length);

Map<String, Object> exampleMap = new HashMap<>();
for (int i = 0; i < parameters.length; i++) {
String paramName = i < parameterNames.length ? parameterNames[i] : "param" + i;
exampleMap.put(paramName, parameters[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.testng.ITestClass;
import org.testng.ITestResult;
import org.testng.ITestNGMethod;
import org.testng.annotations.Parameters;
Expand Down Expand Up @@ -41,18 +42,20 @@ void shouldReturnNullWhenNoParameters() {
}

@Test
@DisplayName("Should return single parameter directly")
void shouldReturnSingleParameterDirectly() {
// Given
@DisplayName("Should return map for a single parameter")
void shouldReturnMapForSingleParameter() {
ITestResult testResult = mock(ITestResult.class);
String parameter = "testValue";
when(testResult.getParameters()).thenReturn(new Object[]{parameter});
when(testResult.getParameters()).thenReturn(
new Object[]{"testValue"});

// When
Object result = extractor.extractExample(testResult);

// Then
assertEquals(parameter, result);
assertNotNull(result);
assertTrue(result instanceof Map);

Map<String, Object> resultMap = (Map<String, Object>) result;
assertEquals(1, resultMap.size());
assertEquals("testValue", resultMap.get("param0"));
}

@Test
Expand Down Expand Up @@ -237,4 +240,157 @@ private void dummyMethodWithoutAnnotation(String param0, Integer param1) {
@SuppressWarnings("unused")
private void dummyMethodWithAnnotation(String username, Integer age) {
}

@Test
@DisplayName("Should preserve null parameter values")
void shouldPreserveNullParameterValues() throws Exception {
ITestResult testResult = mock(ITestResult.class);
ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
ConstructorOrMethod constructorOrMethod =
mock(ConstructorOrMethod.class);

Method method = TestNgParameterExtractorTest.class
.getDeclaredMethod(
"dummyMethodWithoutAnnotation",
String.class,
Integer.class);

when(testResult.getParameters()).thenReturn(
new Object[]{null, 123});
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod())
.thenReturn(constructorOrMethod);
when(constructorOrMethod.getMethod()).thenReturn(method);

Object result = extractor.extractExample(testResult);

assertNotNull(result);
assertTrue(result instanceof Map);

Map<String, Object> resultMap = (Map<String, Object>) result;
assertTrue(resultMap.containsKey("param0"));
assertNull(resultMap.get("param0"));
assertEquals(123, resultMap.get("param1"));
}

@Test
@DisplayName("Should fall back when annotation has fewer names")
void shouldFallbackWhenAnnotationHasFewerNames() throws Exception {
ITestResult testResult = mock(ITestResult.class);
ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
ConstructorOrMethod constructorOrMethod =
mock(ConstructorOrMethod.class);

Method method = TestNgParameterExtractorTest.class
.getDeclaredMethod(
"dummyMethodWithIncompleteAnnotation",
String.class,
Integer.class,
boolean.class);

when(testResult.getParameters()).thenReturn(
new Object[]{"Alice", 30, true});
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testNGMethod.getConstructorOrMethod())
.thenReturn(constructorOrMethod);
when(constructorOrMethod.getMethod()).thenReturn(method);

Object result = extractor.extractExample(testResult);

assertNotNull(result);
assertTrue(result instanceof Map);

Map<String, Object> resultMap = (Map<String, Object>) result;
assertEquals(3, resultMap.size());
assertEquals("Alice", resultMap.get("param0"));
assertEquals(30, resultMap.get("param1"));
assertEquals(true, resultMap.get("param2"));
}

@Test
@DisplayName("Should use annotation names in RID")
void shouldUseAnnotationNamesInRid() throws Exception {
ITestResult testResult = mock(ITestResult.class);
ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
ITestClass testClass = mock(ITestClass.class);
ConstructorOrMethod constructorOrMethod =
mock(ConstructorOrMethod.class);

Method method = TestNgParameterExtractorTest.class
.getDeclaredMethod(
"dummyMethodWithAnnotation",
String.class,
Integer.class);

when(testResult.getParameters()).thenReturn(
new Object[]{"Alice", 25});
when(testResult.getTestClass()).thenReturn(testClass);
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testClass.getName()).thenReturn("com.example.TestClass");
when(testNGMethod.getMethodName()).thenReturn("testMethod");
when(testNGMethod.getConstructorOrMethod())
.thenReturn(constructorOrMethod);
when(constructorOrMethod.getMethod()).thenReturn(method);

String rid = extractor.generateRid(testResult);

assertEquals(
"com.example.TestClass.testMethod-username_Alice-age_25",
rid);
}

@Test
@DisplayName("Should handle empty string parameter")
void shouldHandleEmptyStringParameter() throws Exception {
ITestResult testResult = mock(ITestResult.class);
ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
ITestClass testClass = mock(ITestClass.class);
ConstructorOrMethod constructorOrMethod =
mock(ConstructorOrMethod.class);

Method method = TestNgParameterExtractorTest.class
.getDeclaredMethod(
"dummyMethodWithoutAnnotation",
String.class,
Integer.class);

when(testResult.getParameters()).thenReturn(new Object[]{""});
when(testResult.getTestClass()).thenReturn(testClass);
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testClass.getName()).thenReturn("com.example.TestClass");
when(testNGMethod.getMethodName()).thenReturn("testMethod");
when(testNGMethod.getConstructorOrMethod())
.thenReturn(constructorOrMethod);
when(constructorOrMethod.getMethod()).thenReturn(method);

assertEquals(
"com.example.TestClass.testMethod-param0_h0",
extractor.generateRid(testResult));
}

@Test
@DisplayName("Should handle null parameters array")
void shouldHandleNullParametersArray() {
ITestResult testResult = mock(ITestResult.class);
ITestNGMethod testNGMethod = mock(ITestNGMethod.class);
ITestClass testClass = mock(ITestClass.class);

when(testResult.getParameters()).thenReturn(null);
when(testResult.getTestClass()).thenReturn(testClass);
when(testResult.getMethod()).thenReturn(testNGMethod);
when(testClass.getName()).thenReturn("com.example.TestClass");
when(testNGMethod.getMethodName()).thenReturn("testMethod");

assertEquals(
"com.example.TestClass.testMethod",
extractor.generateRid(testResult));
}



@Parameters({"username"})
@SuppressWarnings("unused")
private void dummyMethodWithIncompleteAnnotation(String username, Integer age, boolean active) {

}
}
4 changes: 2 additions & 2 deletions testomat-allure-adapter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>testomat-allure-adapter</artifactId>
<version>0.1.8</version>
<version>0.1.9</version>
<packaging>jar</packaging>

<name>Testomat.io Testomat Allure adapter</name>
Expand Down Expand Up @@ -67,7 +67,7 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.19.0</version>
<version>0.19.1</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
Expand Down
Loading