diff --git a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java index ebbc0a63e..db318072b 100644 --- a/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java +++ b/allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java @@ -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; @@ -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; @@ -779,9 +781,23 @@ private List 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 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++) { @@ -797,8 +813,8 @@ private List 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])); } } diff --git a/allure-testng/src/test/java/io/qameta/allure/testng/samples/ParameterizedTest.java b/allure-testng/src/test/java/io/qameta/allure/testng/samples/ParameterizedTest.java index 385689b14..2f7751130 100644 --- a/allure-testng/src/test/java/io/qameta/allure/testng/samples/ParameterizedTest.java +++ b/allure-testng/src/test/java/io/qameta/allure/testng/samples/ParameterizedTest.java @@ -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 ehborisov@gmail.com */ @@ -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; + }); } } diff --git a/allure-testng/src/test/resources/suites/parameterized-test.xml b/allure-testng/src/test/resources/suites/parameterized-test.xml index 6911eb613..ce3abb24d 100644 --- a/allure-testng/src/test/resources/suites/parameterized-test.xml +++ b/allure-testng/src/test/resources/suites/parameterized-test.xml @@ -2,10 +2,12 @@ + + + - - +