testNG helloWorld

1. 新建maven工程。File -> New -> Project -> Maven,不选Create from archetype,直接点击“Next”。GroupId和ArtifactId填TestHelloWorld。点击确认,完成新建。

2. src -> main -> java下新建java文件,内容如下:

public class RandomEmailGenerator {

    public String emailGenerator(){
return "Have generate an email";
}
}

3. src -> test -> java下新建java文件,内容如下:

import org.testng.Assert;
import org.testng.annotations.Test; public class TestHelloWorld { @Test
public void testEmailGenerator(){
RandomEmailGenerator randomEmailGenerator = new RandomEmailGenerator();
String email = randomEmailGenerator.emailGenerator(); Assert.assertEquals(email, "Have generate an email");
}
}

4. pom.xml文件

<?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> <groupId>TestHelloWorld</groupId>
<artifactId>TestHelloWorld</artifactId>
<version>1.0-SNAPSHOT</version> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies> </project>

5. 配置工程。

选择TestNG,class里选择TestHellWorld.java文件。

testNG helloWorld

6. 运行

点击unname旁边的三角符号,将运行testNG测试用例。运行结果如下。

testNG helloWorld

上一篇:Hive通过自定义UDF函数实现分词


下一篇:JAVA+SELENIUM+MAVEN+TESTNG框架(二)新建项目