-
Notifications
You must be signed in to change notification settings - Fork 53.5k
Expand file tree
/
Copy pathDataDrivenNameTest.java
More file actions
37 lines (29 loc) · 1.28 KB
/
Copy pathDataDrivenNameTest.java
File metadata and controls
37 lines (29 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.baeldung.testng;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class DataDrivenNameTest {
private static final Logger logger = LoggerFactory.getLogger(DataDrivenNameTest.class);
private String testName;
@BeforeMethod
public void capture(Method method, Object[] params) {
String testName = method.getName() + Arrays.toString(params);
this.testName = testName;
logger.info("Executing test {}", testName);
}
@Test(dataProvider = "numbers")
public void givenInputParameters_WhenFetchingTestName_ThenShouldReturnCorrectTestName(int input, int expected) {
logger.info("Executing scenario from {}", testName);
Assert.assertListContainsObject(List.of("givenInputParameters_WhenFetchingTestName_ThenShouldReturnCorrectTestName[2, 4]", "givenInputParameters_WhenFetchingTestName_ThenShouldReturnCorrectTestName[3, 9]"), testName, "Test name is not as expected");
}
@DataProvider
public Object[][] numbers() {
return new Object[][] { { 2, 4 }, { 3, 9 } };
}
}