[JAVA-10432] Rename and enable testng-command-line module

This commit is contained in:
Haroon Khan
2022-03-04 21:17:23 +00:00
parent 8c63a8e145
commit 2bdc9bf90d
6 changed files with 8 additions and 6 deletions

View File

@@ -0,0 +1,3 @@
### Relevant articles
- [Running a TestNG Project From the Command Line](https://www.baeldung.com/testng-run-command-line)

View File

@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>testng-command-line</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>testng-command-line</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>testing-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>${com.beust.jcommander.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>${org.webjars.jquery.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven.clean.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>ExecuteSingleTest</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
<includes>
<include>**/DateSerializerServiceUnitTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
<profile>
<id>ExecuteTestSuite</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<testng.version>7.4.0</testng.version>
<com.beust.jcommander.version>1.81</com.beust.jcommander.version>
<org.webjars.jquery.version>3.5.1</org.webjars.jquery.version>
<maven.clean.plugin.version>3.1.0</maven.clean.plugin.version>
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.22.1</maven.surefire.plugin.version>
</properties>
</project>

View File

@@ -0,0 +1,11 @@
package com.baeldung.testng;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateSerializerService {
public String serializeDate(Date date, String format) {
SimpleDateFormat dateFormat = new SimpleDateFormat(format);
return dateFormat.format(date);
}
}

View File

@@ -0,0 +1,24 @@
package com.baeldung.testng;
import java.util.Date;
import com.baeldung.testng.DateSerializerService;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
@Test(testName = "Date Serializer")
public class DateSerializerServiceUnitTest {
private DateSerializerService toTest;
@BeforeClass
public void beforeClass() {
toTest = new DateSerializerService();
}
@Test(expectedExceptions = { NullPointerException.class })
void givenNullDate_whenSerializeDate_thenThrowsException() {
Date dateToTest = null;
toTest.serializeDate(dateToTest, "yyyy/MM/dd HH:mm:ss.SSS");
}
}

View File

@@ -0,0 +1,10 @@
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="TestNG command-line" verbose="10">
<test name="Date Serializer">
<classes>
<class
name="com.baeldung.testng.DateSerializerServiceUnitTest" />
</classes>
</test>
</suite>