Skip to content

Commit bd5e286

Browse files
committed
Include parameterized TestNG tests
1 parent 5d01abe commit bd5e286

File tree

7 files changed

+99
-9
lines changed

7 files changed

+99
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ target
1111
build
1212
allure-results
1313
bin
14+
test-output

junit-vs-testng/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
<version>3.5.3</version>
7777
</dependency>
7878
</dependencies>
79+
<configuration>
80+
<suiteXmlFiles>
81+
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
82+
</suiteXmlFiles>
83+
</configuration>
7984
</plugin>
8085
</plugins>
8186
</build>

junit-vs-testng/src/test/java/io/github/bonigarcia/junit/HelloWorldJUnitTest.java renamed to junit-vs-testng/src/test/java/io/github/bonigarcia/junit/basic/HelloWorldJUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
*
1616
*/
1717
package io.github.bonigarcia.junit;
18+
package io.github.bonigarcia.junit.basic;
1819

1920
import static org.assertj.core.api.Assertions.assertThat;
2021

21-
import org.testng.annotations.Test;
22+
import org.junit.jupiter.api.Test;
2223

2324
class HelloWorldJUnitTest {
2425

junit-vs-testng/src/test/java/io/github/bonigarcia/testng/HelloWorldNGTest.java renamed to junit-vs-testng/src/test/java/io/github/bonigarcia/testng/basic/HelloWorldNGTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*
1616
*/
17-
package io.github.bonigarcia.testng;
17+
package io.github.bonigarcia.testng.basic;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
2020

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* (C) Copyright 2021 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia.testng.parameterized;
18+
19+
import org.testng.annotations.DataProvider;
20+
import org.testng.annotations.Test;
21+
22+
public class ParameterizedDataProviderNGTest {
23+
24+
@DataProvider(name = "loginData")
25+
public static Object[][] data() {
26+
return new Object[][] { { "user", "user", "Login successful" },
27+
{ "bad-user", "bad-passwd", "Invalid credentials" } };
28+
}
29+
30+
@Test(dataProvider = "loginData")
31+
public void testParameterized(String username, String password,
32+
String expectedText) {
33+
System.out
34+
.println(String.format("Logging in with %s:%s (expecting '%s')",
35+
username, password, expectedText));
36+
}
37+
38+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* (C) Copyright 2025 Boni Garcia (https://bonigarcia.github.io/)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
package io.github.bonigarcia.testng.parameterized;
18+
19+
import org.testng.annotations.Parameters;
20+
import org.testng.annotations.Test;
21+
22+
public class ParameterizedXmlNGTest {
23+
24+
@Test
25+
@Parameters({ "username", "password" })
26+
public void test(String username, String password) {
27+
System.out.println("Logging in with " + username + ":" + password);
28+
}
29+
30+
}
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
2-
<suite name="parallel-suite" parallel="classes" thread-count="2">
3-
<test name="parallel-tests">
1+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
2+
<suite name="TestSuite" verbose="1" parallel="false">
3+
<test name="RegularTests">
4+
<packages>
5+
<package name="io.github.bonigarcia.testng.basic" />
6+
<package name="io.github.bonigarcia.testng.parameterized">
7+
<classes>
8+
<class
9+
name="io.github.bonigarcia.testng.parameterized.ParameterizedXmlNGTest">
10+
<methods>
11+
<exclude name=".*" />
12+
</methods>
13+
</class>
14+
</classes>
15+
</package>
16+
</packages>
17+
</test>
18+
<test name="ParameterizedTests">
19+
<parameter name="username" value="admin" />
20+
<parameter name="password" value="secret" />
421
<classes>
522
<class
6-
name="io.github.bonigarcia.webdriver.testng.ch08.parallel.Parallel1NGTest" />
7-
<class
8-
name="io.github.bonigarcia.webdriver.testng.ch08.parallel.Parallel2NGTest" />
23+
name="io.github.bonigarcia.testng.parameterized.ParameterizedXmlNGTest" />
924
</classes>
1025
</test>
11-
</suite>
26+
</suite>

0 commit comments

Comments
 (0)