TestNG Learning - Running a Test Instance

I talked a lot about testng earlier. Today, based on previous learning and understanding, I will try to run a test instance to familiarize myself with the specific use.

TestNG can usually be called in the following ways:

命令行antEclipseIntelliJ IDEA

At present, since IntelliJ IDEA is used a lot, the call operation under IntelliJ IDEA is taken as an example to explain.

1) Preparation

First create a testng maven project, and then create a testng.xml file      according to the previous article TestNG learning-testng.xml .

2) Create an instance of your own, for example:​​​​​​​​

public class testExample {
   
     //该方法为力扣第5654题的一个解答  public int countBalls(int lowLimit, int highLimit) {
   
       int[] result = new int[54];    for (int i = lowLimit; i <= highLimit; i++) {
   
         int count = 0;      int temp = i;      while (temp > 0) {
   
           count += temp % 10;        temp = temp / 10;      }      result[count - 1]++;    }    int max = 0;    for (int i = 0; i < 54; i++) {
   
         if (result[i] > max) {
   
           max = result[i];      }    }    return max;  }}

3) Create the corresponding test case as follows, let's use a simple result verification as an example to illustrate:​​​​​​​​

import org.testng.Assert;import org.testng.annotations.Test;
public class testExampleTest {
   
     testExample test1 = new testExample();  @Test  public void test1() {
   
       Assert.assertEquals(test1.countBalls(1, 10), 3);  }}

4) Execute the test case, and verify the result with mvn test:

picture

As shown in the figure above, the result of the test case execution is 2, but we expect to fill in 3, which does not match the result, and an error is output. Next, modify the expected result to 2, and then run mvn test to execute successfully. As shown below:

picture

 

The above is the initial execution process of testng in the maven project, and then we will conduct further exploration. Welcome to pay attention to exchanges and make progress together~

Welcome to pay attention to the WeChat public account [Test Memo], view more content, and communicate together

Guess you like

Origin blog.csdn.net/hashsabr/article/details/113811498