Skip to content

Commit

Permalink
Fix for allure-framework#893 - param annotation name not coming up in…
Browse files Browse the repository at this point in the history
… report
  • Loading branch information
mr-possible committed Sep 22, 2024
1 parent 3d361dd commit b85e6ae
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.qameta.allure.Muted;
import io.qameta.allure.Severity;
import io.qameta.allure.SeverityLevel;
import io.qameta.allure.Param;
import io.qameta.allure.model.FixtureResult;
import io.qameta.allure.model.Label;
import io.qameta.allure.model.Link;
Expand Down Expand Up @@ -74,6 +75,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static io.qameta.allure.util.ResultsUtils.ALLURE_ID_LABEL_NAME;
Expand Down Expand Up @@ -779,9 +781,23 @@ private List<Parameter> getParameters(final ITestContext context,
.map(Parameters::value)
.orElse(new String[]{});

final String[] reflectionNames = Stream.of(m.getParameters())
.map(java.lang.reflect.Parameter::getName)
.toArray(String[]::new);
final List<Parameter> reflectionNames = IntStream
.range(0, parameters.length)
.mapToObj(index -> {
final Parameter parameter = createParameter(m.getParameters()[index].getName(), parameters[index]);
Stream.of(m.getParameters()[index].getAnnotationsByType(Param.class))
.findFirst()
.ifPresent(param -> {
Stream.of(param.name().trim())
.map(String::trim)
.filter(name -> !name.isEmpty())
.findFirst()
.ifPresent(parameter::setName);
parameter.setMode(param.mode());
parameter.setExcluded(param.excluded());
});
return parameter;
}).collect(Collectors.toList());

int skippedCount = 0;
for (int i = 0; i < parameterTypes.length; i++) {
Expand All @@ -797,8 +813,8 @@ private List<Parameter> getParameters(final ITestContext context,
continue;
}

if (i < reflectionNames.length) {
result.put(reflectionNames[i], ObjectUtils.toString(parameters[i]));
if (i < reflectionNames.size()) {
result.put(reflectionNames.get(i).getName(), ObjectUtils.toString(parameters[i]));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package io.qameta.allure.testng.samples;

import io.qameta.allure.Step;
import io.qameta.allure.Param;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import static io.qameta.allure.Allure.step;

/**
* @author Egor Borisov [email protected]
*/
Expand All @@ -38,13 +40,36 @@ public Object[][] testData() {
};
}

@DataProvider
public static Object[][] testDataForParamNames() {
return new Object[][]{
{1, 1, 2, 5},
{2, 2, 4, 5}
};
}

@Test(dataProvider = "testData")
public void parameterizedTest(String param) {
step(param);
}

@Step
public void step(String param) {
@Test(dataProvider = "testDataForParamNames")
public void sumTest(
@Param(name = "First") Integer a,
@Param(name = "Second") Integer b,
@Param(name = "Third") Integer r,
@Param(name = "Fourth") Integer s) {

step(("Arrange"), () -> {
step(String.format("Take collection №[%s] of parameters", a));
});
step(("Act"), () -> {
step(String.format("Add [%s]", a) + String.format("to [%s]", b));
});
step(("Assert"), () -> {
step("Compare the sum");
assert a + b == r;
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Test suite 6">
<listeners>
<listener class-name="io.qameta.allure.testng.AllureTestNg"/>
</listeners>
<test name="Test tag 6">
<classes>
<class name="io.qameta.allure.testng.samples.ParameterizedTest">
</class>
<class name="io.qameta.allure.testng.samples.ParameterizedTest"/>
</classes>
</test>
</suite>

0 comments on commit b85e6ae

Please sign in to comment.