精华内容
下载资源
问答
  • TestNG教程

    2015-11-09 13:50:05
    TestNG介绍文档,说明框架的使用方法及注解。
  • testng教程_TestNG教程

    2020-07-12 07:24:52
    testng教程TestNG is a testing framework for Java application that is inspired from JUnit and NUnit. TestNG是一个受JUnit和NUnit启发的Java应用程序测试框架。 测试NG (TestNG) TestNG provides many ...

    testng教程

    TestNG is a testing framework for Java application that is inspired from JUnit and NUnit.

    TestNG是一个受JUnit和NUnit启发的Java应用程序测试框架。

    测试NG (TestNG)

    TestNG provides many features that makes it easy to write and run test cases:

    TestNG提供了许多功能,使编写和运行测试用例变得容易:

    • Annotation based

      基于注释
    • Plugins for major IDEs such as Eclipse and IDEA.

      适用于主要IDE(例如Eclipse和IDEA)的插件。
    • Automatically creation of test suites

      自动创建测试套件
    • HTML based report generation

      基于HTML的报告生成
    • Ability to run single test method using IDE plugins.

      能够使用IDE插件运行单一测试方法。
    • Data driven testing using @DataProvider

      使用@DataProvider数据驱动的测试
    • No additional dependencies to run and logging

      无需其他依赖来运行和记录
    • TestNG XML file to run test suites with different configurations

      TestNG XML文件以运行具有不同配置的测试套件

    TestNG Maven依赖 (TestNG Maven Dependency)

    TestNG libraries are present on maven repository, you can add below maven dependency to include TestNG in your project.

    TestNG库存在于maven存储库中,您可以在maven依赖项下面添加以在您的项目中包含TestNG。

    <dependency>
    	<groupId>org.testng</groupId>
    	<artifactId>testng</artifactId>
    	<version>6.14.3</version>
    	<scope>test</scope>
    </dependency>

    TestNG Eclipse插件 (TestNG Eclipse Plugin)

    I am using Eclipse for TestNG example project, so let’s first install TestNG Eclipse plugin.

    我正在使用Eclipse for TestNG示例项目,因此让我们首先安装TestNG Eclipse插件。

    Go to “Eclipse Marketplace” and search for “TestNG”.

    转到“ Eclipse Marketplace”并搜索“ TestNG”。

    Click on “Install” and go through further screens to install it. You will have to accept its license agreement and restart Eclipse once installation is finished.

    单击“安装”,然后通过其他屏幕进行安装。 安装完成后,您将必须接受其许可协议并重新启动Eclipse。

    Go to “Window | Show View | Other” and inside “Java” you should see “TestNG”.

    转到“窗口| 显示视图 其他”和“ Java”中,您应该看到“ TestNG”。

    This means that TestNG for Eclipse is successfully installed and we are ready to create our TestNG test classes.

    这意味着TestNG for Eclipse已成功安装,并且我们准备创建TestNG测试类。

    创建TestNG类 (Create TestNG Class)

    Go to your project in the explorer and click on “New | Other” and select “TestNG Class” and click Next.

    在资源管理器中转到您的项目,然后单击“新建| 其他”,然后选择“ TestNG类”,然后单击“下一步”。

    In next screen, we have to specify our TestNG class configurations and select annotations to include in the class and click on Finish button.

    在下一个屏幕中,我们必须指定我们的TestNG类配置,并选择要包括在类中的注释,然后单击“完成”按钮。

    This will generate TestNG skeleton class like below.

    这将生成如下的TestNG骨架类。

    package com.journaldev.utils;
    
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.AfterSuite;
    
    public class TestUtils {
      @Test(dataProvider = "dp")
      public void f(Integer n, String s) {
      }
      @BeforeMethod
      public void beforeMethod() {
      }
    
      @AfterMethod
      public void afterMethod() {
      }
    
    
      @DataProvider
      public Object[][] dp() {
        return new Object[][] {
          new Object[] { 1, "a" },
          new Object[] { 2, "b" },
        };
      }
      @BeforeClass
      public void beforeClass() {
      }
    
      @AfterClass
      public void afterClass() {
      }
    
      @BeforeTest
      public void beforeTest() {
      }
    
      @AfterTest
      public void afterTest() {
      }
    
      @BeforeSuite
      public void beforeSuite() {
      }
    
      @AfterSuite
      public void afterSuite() {
      }
    
    }

    That’s it, we can run our basic TestNG class by going to “Run As | TestNG Test” as shown in below image.

    就这样,我们可以通过运行“ Run As | TestNG测试”,如下图所示。

    Since our test class has nothing, it should pass all tests. You can check “Console” for the logs generated and “TestNG View” will show you basic details of your test run.

    由于我们的测试类没有任何内容,因此它应该通过所有测试。 您可以检查“控制台”中生成的日志,“ TestNG View”将向您显示测试运行的基本详细信息。

    TestNG测试套件流程 (TestNG Test Suite Flow)

    I have added some console logging in the annotated methods to understand the flow of TestNG test run.

    我在带注释的方法中添加了一些控制台日志记录,以了解TestNG测试运行的流程。

    package com.journaldev.utils;
    
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeTest;
    import org.testng.annotations.AfterTest;
    import org.testng.annotations.BeforeSuite;
    import org.testng.annotations.AfterSuite;
    
    public class TestUtils {
      @Test(dataProvider = "dp")
      public void f(Integer n, String s) {
    	  System.out.println("Inside @Test");
      }
      @BeforeMethod
      public void beforeMethod() {
    	  System.out.println("Inside @BeforeMethod");
      }
    
      @AfterMethod
      public void afterMethod() {
    	  System.out.println("Inside @AfterMethod");
      }
    
    
      @DataProvider
      public Object[][] dp() {
    	  System.out.println("Inside @DataProvider");
        return new Object[][] {
          new Object[] { 1, "a" },
          new Object[] { 2, "b" },
        };
      }
      @BeforeClass
      public void beforeClass() {
    	  System.out.println("Inside @BeforeClass");
      }
    
      @AfterClass
      public void afterClass() {
    	  System.out.println("Inside @AfterClass");
      }
    
      @BeforeTest
      public void beforeTest() {
    	  System.out.println("Inside @BeforeTest");
      }
    
      @AfterTest
      public void afterTest() {
    	  System.out.println("Inside @AfterTest");
      }
    
      @BeforeSuite
      public void beforeSuite() {
    	  System.out.println("Inside @BeforeSuite");
      }
    
      @AfterSuite
      public void afterSuite() {
    	  System.out.println("Inside @AfterSuite");
      }
    
    }

    When I run it again, below console logs are generated.

    当我再次运行它时,在控制台日志下面生成。

    [RemoteTestNG] detected TestNG version 6.14.3
    Inside @BeforeSuite
    Inside @BeforeTest
    Inside @BeforeClass
    Inside @DataProvider
    Inside @BeforeMethod
    Inside @Test
    Inside @AfterMethod
    Inside @BeforeMethod
    Inside @Test
    Inside @AfterMethod
    Inside @AfterClass
    Inside @AfterTest
    PASSED: f(1, "a")
    PASSED: f(2, "b")
    
    ===============================================
        Default test
        Tests run: 2, Failures: 0, Skips: 0
    ===============================================
    
    Inside @AfterSuite
    
    ===============================================
    Default suite
    Total tests run: 2, Failures: 0, Skips: 0
    ===============================================

    Based on above output, we can deduce the flow of TestNG test as:

    根据上面的输出,我们可以推断出TestNG测试的流程为:

    BeforeSuite -> BeforeTest -> BeforeClass -> DataProvider -> 
    { BeforeMethod -> Test -> AfterMethod } * N 
    -> AfterClass -> AfterTest -> AfterSuite

    N is the number of times our test method is executed and it depends on the number of inputs generated by @DataProvider method.

    N是测试方法执行的次数,它取决于@DataProvider方法生成的输入数。

    We can use @BeforeXXX methods for some preprocessing and initialize resources that we want to use in the test suite. Similarly, we can use @AfterXXX methods for post-processing and closing resources.

    我们可以使用@BeforeXXX方法进行一些预处理,并初始化要在测试套件中使用的资源。 同样,我们可以使用@AfterXXX方法进行后处理和关闭资源。

    TestNG教程 (TestNG Tutorial)

    Now that we have gone through the basics of TestNG and set it up in Eclipse, let’s create a class with few methods and use TestNG to run some test cases on it.

    现在,我们已经了解了TestNG的基础知识并在Eclipse中进行了设置,让我们创建一个几乎没有方法的类,并使用TestNG在其上运行一些测试用例。

    package com.journaldev.utils;
    
    public class Utils {
    
    	public static String NAME = "";
    
    	public int add(int x, int y) {
    		return x + y;
    	}
    
    	public int subtract(int x, int y) {
    		return x - y;
    	}
    
    	public static void setName(String s) {
    		System.out.println("Setting NAME to " + s);
    		NAME = s;
    	}
    }

    I have added few public methods, static and void methods too. Below is my TestNG class to test these methods.

    我还添加了一些公共方法,静态方法和无效方法。 下面是我的TestNG类,用于测试这些方法。

    package com.journaldev.utils;
    
    import org.testng.Assert;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    public class TestUtils {
    	@Test(dataProvider = "dp")
    	public void test_add(Integer x, Integer y) {
    		Utils u = new Utils();
    		Assert.assertEquals(u.add(x, y), x + y);
    	}
    
    	@Test(dataProvider = "dp")
    	public void test_subtract(Integer x, Integer y) {
    		Utils u = new Utils();
    		Assert.assertEquals(u.subtract(x, y), x - y);
    	}
    
    	@Test(dataProvider = "dpName")
    	public void test_setName(String s) {
    		Utils.setName(s);
    		Assert.assertEquals(Utils.NAME, s);
    	}
    
    	@DataProvider
    	public Object[][] dp() {
    		return new Object[][] { new Object[] { 1, 1 }, new Object[] { 2, 2 }, };
    	}
    
    	@DataProvider
    	public Object[][] dpName() {
    		return new Object[][] { new Object[] { "Utils" }, new Object[] { "MyUtils" }, };
    	}
    
    }

    Now when we run above class as TestNG Test, we get following output in console.

    现在,当我们在类上方运行TestNG Test时,将在控制台中获得以下输出。

    [RemoteTestNG] detected TestNG version 6.14.3
    Setting NAME to Utils
    Setting NAME to MyUtils
    PASSED: test_add(1, 1)
    PASSED: test_add(2, 2)
    PASSED: test_setName("Utils")
    PASSED: test_setName("MyUtils")
    PASSED: test_subtract(1, 1)
    PASSED: test_subtract(2, 2)
    
    ===============================================
        Default test
        Tests run: 6, Failures: 0, Skips: 0
    ===============================================
    
    
    ===============================================
    Default suite
    Total tests run: 6, Failures: 0, Skips: 0
    ===============================================

    Refresh the project and you will see a newly generated directory test-output.

    刷新项目,您将看到一个新生成的目录test-output

    Open index.html in any browser and you should see HTML report like below image.

    在任何浏览器中打开index.html ,您应该看到如下图所示HTML报告。

    TestNG XML套件 (TestNG XML Suite)

    One of the best part of TestNG is the auto generation of test suite xml file.

    TestNG最好的部分之一是自动生成测试套件xml文件。

    We can edit it and add parameters to it, we can use it to run a single test method too. TestNG XML suite provides a lot of options and it’s very useful when you want to run a test case through the command line, such as on server with no Eclipse. We can run the TestNG test suite xml file using below command:

    我们可以对其进行编辑并添加参数,也可以使用它来运行单个测试方法。 TestNG XML套件提供了很多选项,当您想通过命令行运行测试用例时(例如在没有Eclipse的服务器上),它非常有用。 我们可以使用以下命令运行TestNG测试套件xml文件:

    $java com.journaldev.utils.TestUtils testng.xml

    TestNG XML is a very vast topic, if you want to explore more then go through its documentation.

    TestNG XML是一个非常广泛的主题,如果您想探索更多内容,请阅读其文档

    TestNG运行单一测试方法 (TestNG Running Single Test Method)

    We can run a single test method too, this is very helpful when our test class has many methods and we are interested in only to test a few of them.

    我们也可以运行一个测试方法,当我们的测试类有很多方法并且我们只想测试其中一些方法时,这将非常有用。

    TestNG测试失败 (TestNG Testing with Failures)

    Let’s see what happens when a bug is introduced in our code, change the Utils class setName method as below.

    让我们看看在代码中引入错误时会发生什么,如下更改Utils类的setName方法。

    public static void setName(String s) {
    	System.out.println("Setting NAME to " + s);
    	// NAME = s; //introducing bug intentionally
    }

    Now when we run the test class again, we get following output in console.

    现在,当我们再次运行测试类时,将在控制台中获得以下输出。

    [RemoteTestNG] detected TestNG version 6.14.3
    Setting NAME to Utils
    Setting NAME to MyUtils
    FAILED: test_setName("Utils")
    java.lang.AssertionError: expected [Utils] but found []
    	at org.testng.Assert.fail(Assert.java:96)
    	at org.testng.Assert.failNotEquals(Assert.java:776)
    	at org.testng.Assert.assertEqualsImpl(Assert.java:137)
    	at org.testng.Assert.assertEquals(Assert.java:118)
    	at org.testng.Assert.assertEquals(Assert.java:453)
    	at org.testng.Assert.assertEquals(Assert.java:463)
    	at com.journaldev.utils.TestUtils.test_setName(TestUtils.java:23)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    	at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    	at org.testng.TestRunner.privateRun(TestRunner.java:648)
    	at org.testng.TestRunner.run(TestRunner.java:505)
    	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    	at org.testng.TestNG.runSuites(TestNG.java:1049)
    	at org.testng.TestNG.run(TestNG.java:1017)
    	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
    
    FAILED: test_setName("MyUtils")
    java.lang.AssertionError: expected [MyUtils] but found []
    	at org.testng.Assert.fail(Assert.java:96)
    	at org.testng.Assert.failNotEquals(Assert.java:776)
    	at org.testng.Assert.assertEqualsImpl(Assert.java:137)
    	at org.testng.Assert.assertEquals(Assert.java:118)
    	at org.testng.Assert.assertEquals(Assert.java:453)
    	at org.testng.Assert.assertEquals(Assert.java:463)
    	at com.journaldev.utils.TestUtils.test_setName(TestUtils.java:23)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    	at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    	at org.testng.TestRunner.privateRun(TestRunner.java:648)
    	at org.testng.TestRunner.run(TestRunner.java:505)
    	at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    	at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    	at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    	at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    	at org.testng.TestNG.runSuites(TestNG.java:1049)
    	at org.testng.TestNG.run(TestNG.java:1017)
    	at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
    	at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    	at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)

    Did you noticed that I am running test only on setName method.:)

    您是否注意到我仅在setName方法上运行测试。:)

    从命令行运行TestNG测试 (Running TestNG Tests from Command Line)

    It’s good that we can run our test cases from Eclipse, but most of the times we want to run all the test cases of the project when building the project. Well, maven automatically runs the test cases for us. Below images show output of mvn clean install command.

    可以从Eclipse运行我们的测试用例是一件好事,但是大多数时候,我们希望在构建项目时运行项目的所有测试用例。 好吧,Maven会自动为我们运行测试用例。 下图显示了mvn clean install命令的输出。

    Success Case

    maven testng test cases run success

    成功案例

    Failure Case

    maven testng test cases run failure

    失败案例

    TestNG测试用例顺序 (TestNG Test Cases Order)

    TestNG test cases are run in the order of their method names. So in our case the order of execution would be: test_add -> test_setName -> test_subtract.

    TestNG测试用例按其方法名称的顺序运行。 因此,在本例中,执行顺序为: test_add -> test_setName -> test_subtract

    We can change the order by setting the priority of test methods. If we want the order of execution as test_add -> test_subtract -> test_setName then we can change our @Test annotation like below.

    我们可以通过设置测试方法的priority来更改顺序。 如果我们希望执行顺序为test_add -> test_subtract -> test_setName则可以如下更改@Test批注。

    @Test(dataProvider = "dp", priority=1)
    public void test_add(Integer x, Integer y) {
    }
    
    @Test(dataProvider = "dp", priority=2)
    public void test_subtract(Integer x, Integer y) {
    }
    
    @Test(dataProvider = "dpName", priority=3)
    public void test_setName(String s) {
    }

    Notice that lower priority methods are executed first.

    请注意,优先级较低的方法会先执行。

    摘要 (Summary)

    TestNG is a very popular unit testing framework and I really liked that it’s very easy to setup and use in the project. We explored basics of TestNG and looked into most common examples to use it in our project.

    TestNG是一个非常流行的单元测试框架,我非常喜欢它在项目中易于设置和使用。 我们探索了TestNG的基础,并研究了最常见的示例以在我们的项目中使用它。

    GitHub Repository. GitHub Repository下载TestNG教程项目。

    翻译自: https://www.journaldev.com/21219/testng-tutorial

    testng教程

    展开全文
  • TestNG教程.pdf

    2019-07-10 16:57:33
    TestNG 是一个测试框架,其灵感来自 JUnit 和 NUnit 的,但引入了一些新的功 能,使其功能更强大,使用更方便。
  • testng 教程

    2019-09-23 08:11:55
    Testng 简介: Testng是一套开源测试框架,是从Junit继承而来,testng意为test next generation,主要有以下特性: annotations 注释,如 @test @BeforeMethod 支持多线程执行case 支持数据驱动 data...

    Testng 简介:

      Testng是一套开源测试框架,是从Junit继承而来,testng意为test next generation,主要有以下特性:

     

    •  annotations  注释,如 @test @BeforeMethod 
    • 支持多线程执行case
    • 支持数据驱动 dataProvider
    • 支持参参数
    • 能够作为eclipse的插件
    • 能够(配合reportng)生产客观的测试报告
    • 可通过testng.xml管理执行case和suite

    那么好的测试框架,怎么使用?

    这里我们使用eclipse插件方式 安装详见:http://testng.org/doc/eclipse.html


    testng使用


    首先了解一下testng 的annotations

    常见的有以下:

    @BeforeClass: 该annotation在class激活之前执行

    @BeforeMethod: 该annotation会在每个执行的方法之前执行

    @Test ,该annotation 是你要执行测试的方法

    @AfterMethod,该annotation在每个测试方法执行之后运行

    @AfterClass 该annotation会在所有测试方法之后运行

    具体生命周期如下图:

    这里是所有的annotation

    @BeforeSuite
    @AfterSuite
    @BeforeTest
    @AfterTest
    @BeforeGroups
    @AfterGroups
    @BeforeClass
    @AfterClass
    @BeforeMethod
    @AfterMethod
    Configuration information for a TestNG class: 

    @BeforeSuite: The annotated method will be run before all tests in this suite have run. 
    @AfterSuite: The annotated method will be run after all tests in this suite have run. 
    @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
    @AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
    @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
    @AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
    @BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
    @AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
    @BeforeMethod: The annotated method will be run before each test method. 
    @AfterMethod: The annotated method will be run after each test method.

    实例:我们验证一下testng annotation 执行顺序,这个case里有两个 测试  ,执行顺序为beforeClass->beforeMethod->test1->afterMethod->beforeMethod->

    test2->afterMethod->afterClass.

    package com.dbyl.tests;
    
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;
    /**
     * This is to verify testng annotation execute 
     * @author Young
     *
     */
    public class TestngExample {
        private int a;
    
        @BeforeMethod(alwaysRun=true)
        public void beforeMethod() {
            a = 2;
            System.out.println("This is beforeMethod method. The Value of a is: "
                    + a);
        }
    
        @BeforeClass
        public void beforeClass() {
            a = 1;
            System.out.println("This is beforeClass method .The Value of a is: "
                    + a);
        }
    
        @Test(groups = "TestngExample")
        public void testExample1() {
            a = 3;
            System.out.println("This is Test  method1 .The Value of a is: " + a);
        }
    
        @Test(groups = "TestngExample")
        public void testExample2() {
            a = 4;
            System.out.println("This is Test  method2 .The Value of a is: " + a);
        }
    
        @AfterClass
        public void afterClass() {
            a = 5;
            System.out.println("This is AfterClass Method .The Value of a is: " + a);
    
        }
        
        @AfterMethod
        public void afterMethod()
        {
            a = 6;
            System.out.println("This is AfterMethod Method .The Value of a is: " + a);
        }
    
    }

     

     所以执行结果为:

     

    This is beforeClass method .The Value of a is: 1
    This is beforeMethod method. The Value of a is: 2
    This is Test method1 .The Value of a is: 3
    This is AfterMethod Method .The Value of a is: 6
    This is beforeMethod method. The Value of a is: 2
    This is Test method2 .The Value of a is: 4
    This is AfterMethod Method .The Value of a is: 6
    This is AfterClass Method .The Value of a is: 5
    PASSED: testExample1
    PASSED: testExample2
    

      当然,还有BeforeSuite 等,不再做深入研究.

    annotation后面可以加一些参数,比如alwaysRun=true/false,dependsOnMethods=""

    alwaysRun控制是否每次都执行,dependsOnMethods是一种依赖,依赖某个方法执行

    之前有提到testng数据驱动,使用dataProvider,dataProvider可以导入text ,excel等数据,

    执行case时会从DataProvider依次拿出数据执行,同一个测试方法,会被执行相应的次数

    package com.dbyl.tests;
    
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    
    public class Case1 {
    
        @DataProvider
        public Object[][] testData1() {
            return new Object[][] { { 1, 2, 3 }, { 1, 2, 4 }, { 1, 3, 4 },
                    { -1, 3, 2 } };
        }
        
    
        @DataProvider
        public Object[][] testData2() {
            return new Object[][] { { 5, 2, 3 }, { 1, 2, 4 }, { 1, -3, 4 },
                    { 6, 3, 2 } };
        }
    
        public static int add(int a, int b) {
            return a + b;
        }
        
        public static int minus(int a, int b) {
            return a - b;
        }
    
        @BeforeClass
        public void beforeClass()
        {
            System.out.println("This is Before Class");
        }
        @Test(groups = { "add" }, dataProvider = "testData1")
        public void addTest(int a, int b, int c) {
            System.out.println("This is test add method.  "+a+" + "+ b+" = "+c);
            Assert.assertEquals(add(a, b), c);
        }
        
        @Test(groups = { "minus" }, dataProvider = "testData2")
        public void minusTest(int a, int b, int c) {
            System.out.println("This is test minus method.  "+a+" - "+ b+" = "+c);
            Assert.assertEquals(minus(a, b), c);
        }
    
        @BeforeMethod
        public void beforeMethod()
        {
            System.out.println("This is Before Method");
        }
        
        @AfterMethod
        public void afterMethod()
        {
            System.out.println("This is After Method");
        }
        
        @AfterClass
        public void afterClass()
        {
            System.out.println("This is After Class");
        }
    }

     

    执行结果如下: 

            

    This is Before Class
    This is Before Method
    This is test add method.  1 + 2 = 3
    This is After Method
    This is Before Method
    This is test add method.  1 + 2 = 4
    This is After Method
    This is Before Method
    This is test add method.  1 + 3 = 4
    This is After Method
    This is Before Method
    This is test add method.  -1 + 3 = 2
    This is After Method
    This is Before Method
    This is test minus method.  5 - 2 = 3
    This is After Method
    This is Before Method
    This is test minus method.  1 - 2 = 4
    This is After Method
    This is Before Method
    This is test minus method.  1 - -3 = 4
    This is After Method
    This is Before Method
    This is test minus method.  6 - 3 = 2
    This is After Method
    This is After Class
    PASSED: addTest(1, 2, 3)
    PASSED: addTest(1, 3, 4)
    PASSED: addTest(-1, 3, 2)
    PASSED: minusTest(5, 2, 3)
    PASSED: minusTest(1, -3, 4)
    FAILED: addTest(1, 2, 4)
    View Code

     


    由于天色已晚,明天继续总结.

    接下来:testng.xml的配置和使用,已经参数传递

               testng配合reportng 生成测试报告

               testng 配合ant

     

    转载于:https://www.cnblogs.com/tobecrazy/p/4579414.html

    展开全文
  • TutorialsPoint TestNG 教程.epub
  • TestNG系列教程:并行执行测试 目录 1. 并行执行测试的优势 2. 如何并行地执行测试方法 3. 如何并行地执行测试类 4. 如何并行地执行同一测试套件内的各个测试组件 5. 如何配置需要在多线程环境中执行的测试方法
  • testNG教程

    2017-03-27 14:02:38
    Testng 简介:  Testng是一套开源测试框架,是从Junit继承而来,testng意为test next generation,主要有以下特性:    annotations 注释,如 @test @BeforeMethod 支持多线程执行case支持数据驱动 data...

    Testng 简介:

      Testng是一套开源测试框架,是从Junit继承而来,testng意为test next generation,主要有以下特性:

     

    •  annotations  注释,如 @test @BeforeMethod 
    • 支持多线程执行case
    • 支持数据驱动 dataProvider
    • 支持参参数
    • 能够作为eclipse的插件
    • 能够(配合reportng)生产客观的测试报告
    • 可通过testng.xml管理执行case和suite

    那么好的测试框架,怎么使用?

    这里我们使用eclipse插件方式 安装详见:http://testng.org/doc/eclipse.html

    testng使用


    首先了解一下testng 的annotations

    常见的有以下:

    @BeforeClass: 该annotation在class激活之前执行

    @BeforeMethod: 该annotation会在每个执行的方法之前执行

    @Test ,该annotation 是你要执行测试的方法

    @AfterMethod,该annotation在每个测试方法执行之后运行

    @AfterClass 该annotation会在所有测试方法之后运行

    具体生命周期如下图:

    这里是所有的annotation

    @BeforeSuite
    @AfterSuite
    @BeforeTest
    @AfterTest
    @BeforeGroups
    @AfterGroups
    @BeforeClass
    @AfterClass
    @BeforeMethod
    @AfterMethod
    Configuration information for a TestNG class: 

    @BeforeSuite: The annotated method will be run before all tests in this suite have run. 
    @AfterSuite: The annotated method will be run after all tests in this suite have run. 
    @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run. 
    @AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run. 
    @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked. 
    @AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked. 
    @BeforeClass: The annotated method will be run before the first test method in the current class is invoked. 
    @AfterClass: The annotated method will be run after all the test methods in the current class have been run. 
    @BeforeMethod: The annotated method will be run before each test method. 
    @AfterMethod: The annotated method will be run after each test method.

    实例:我们验证一下testng annotation 执行顺序,这个case里有两个 测试  ,执行顺序为beforeClass->beforeMethod->test1->afterMethod->beforeMethod->

    test2->afterMethod->afterClass.

    复制代码
    package com.dbyl.tests;
    
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.Test;
    /**
     * This is to verify testng annotation execute 
     * @author Young
     *
     */
    public class TestngExample {
        private int a;
    
        @BeforeMethod(alwaysRun=true)
        public void beforeMethod() {
            a = 2;
            System.out.println("This is beforeMethod method. The Value of a is: "
                    + a);
        }
    
        @BeforeClass
        public void beforeClass() {
            a = 1;
            System.out.println("This is beforeClass method .The Value of a is: "
                    + a);
        }
    
        @Test(groups = "TestngExample")
        public void testExample1() {
            a = 3;
            System.out.println("This is Test  method1 .The Value of a is: " + a);
        }
    
        @Test(groups = "TestngExample")
        public void testExample2() {
            a = 4;
            System.out.println("This is Test  method2 .The Value of a is: " + a);
        }
    
        @AfterClass
        public void afterClass() {
            a = 5;
            System.out.println("This is AfterClass Method .The Value of a is: " + a);
    
        }
        
        @AfterMethod
        public void afterMethod()
        {
            a = 6;
            System.out.println("This is AfterMethod Method .The Value of a is: " + a);
        }
    
    }
    复制代码

     

     所以执行结果为:

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    This is beforeClass method .The Value of a is: 1
    This is beforeMethod method. The Value of a is: 2
    This is Test method1 .The Value of a is: 3
    This is AfterMethod Method .The Value of a is: 6
    This is beforeMethod method. The Value of a is: 2
    This is Test method2 .The Value of a is: 4
    This is AfterMethod Method .The Value of a is: 6
    This is AfterClass Method .The Value of a is: 5
    PASSED: testExample1
    PASSED: testExample2

      当然,还有BeforeSuite 等,不再做深入研究.

    annotation后面可以加一些参数,比如alwaysRun=true/false,dependsOnMethods=""

    alwaysRun控制是否每次都执行,dependsOnMethods是一种依赖,依赖某个方法执行

    之前有提到testng数据驱动,使用dataProvider,dataProvider可以导入text ,excel等数据,

    执行case时会从DataProvider依次拿出数据执行,同一个测试方法,会被执行相应的次数

    复制代码
    package com.dbyl.tests;
    
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.AfterMethod;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.BeforeMethod;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;
    
    
    public class Case1 {
    
        @DataProvider
        public Object[][] testData1() {
            return new Object[][] { { 1, 2, 3 }, { 1, 2, 4 }, { 1, 3, 4 },
                    { -1, 3, 2 } };
        }
        
    
        @DataProvider
        public Object[][] testData2() {
            return new Object[][] { { 5, 2, 3 }, { 1, 2, 4 }, { 1, -3, 4 },
                    { 6, 3, 2 } };
        }
    
        public static int add(int a, int b) {
            return a + b;
        }
        
        public static int minus(int a, int b) {
            return a - b;
        }
    
        @BeforeClass
        public void beforeClass()
        {
            System.out.println("This is Before Class");
        }
        @Test(groups = { "add" }, dataProvider = "testData1")
        public void addTest(int a, int b, int c) {
            System.out.println("This is test add method.  "+a+" + "+ b+" = "+c);
            Assert.assertEquals(add(a, b), c);
        }
        
        @Test(groups = { "minus" }, dataProvider = "testData2")
        public void minusTest(int a, int b, int c) {
            System.out.println("This is test minus method.  "+a+" - "+ b+" = "+c);
            Assert.assertEquals(minus(a, b), c);
        }
    
        @BeforeMethod
        public void beforeMethod()
        {
            System.out.println("This is Before Method");
        }
        
        @AfterMethod
        public void afterMethod()
        {
            System.out.println("This is After Method");
        }
        
        @AfterClass
        public void afterClass()
        {
            System.out.println("This is After Class");
        }
    }
    复制代码

     

    执行结果如下: 

    This is Before Class
    This is Before Method
    This is test add method.  1 + 2 = 3
    This is After Method
    This is Before Method
    This is test add method.  1 + 2 = 4
    This is After Method
    This is Before Method
    This is test add method.  1 + 3 = 4
    This is After Method
    This is Before Method
    This is test add method.  -1 + 3 = 2
    This is After Method
    This is Before Method
    This is test minus method.  5 - 2 = 3
    This is After Method
    This is Before Method
    This is test minus method.  1 - 2 = 4
    This is After Method
    This is Before Method
    This is test minus method.  1 - -3 = 4
    This is After Method
    This is Before Method
    This is test minus method.  6 - 3 = 2
    This is After Method
    This is After Class
    PASSED: addTest(1, 2, 3)
    PASSED: addTest(1, 3, 4)
    PASSED: addTest(-1, 3, 2)
    PASSED: minusTest(5, 2, 3)
    PASSED: minusTest(1, -3, 4)
    FAILED: addTest(1, 2, 4)
    展开全文
  • 昨天学习了一下testng基础教程,http://www.cnblogs.com/tobecrazy/p/4579414.html 昨天主要学习的是testng 的annotation基本用法和生命周
    原文地址为:
    testng教程之testng.xml的配置和使用,以及参数传递
    

    昨天学习了一下testng基础教程,http://www.cnblogs.com/tobecrazy/p/4579414.html

    昨天主要学习的是testng 的annotation基本用法和生命周期,今天学习一下如何使用testng.xml和testng.xml的相关配置

    testng.xml

    testng.xml是为了更方便的管理和执行测试用例,同时也可以结合其他工具

     

    You can invoke TestNG in several different ways: 你可以用以下三种方式执行测试

     

    • With a testng.xml file           直接run as test suite
    • With ant                            使用ant
    • From the command line      从命令行
    • eclipse                              直接在eclipse执行

     


     

    textng.xml 基本格式如下:

    <test name="Regression1">
    <groups>
    <run>
    <exclude name="brokenTests" />
    <include name="checkinTests" />
    </run>
    </groups>

    <classes>
    <class name="test.IndividualMethodsTest">
    <methods>
    <include name="testMethod" />
    </methods>
    </class>
    </classes>
    </test>

    suite:定义一个测试套件,可包含多个测试用例或测试group

    suite 里可以设置是否使用多线程:

      

    parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.


    parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.


    parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.


    parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.

    • parallel="classes"  每个测试用例class级别多线程
    • thread-count="3" 线程数为5,可同时执行3个case
    • preserve-order="true"  根据官方解释(If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to false)设置为false乱序执行,设置为true会按照你配置执行
    • Parameter标签传递参数

                          

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite" parallel="classes" thread-count="3">
    <test verbose="2" preserve-order="true" name="TestDebug">
    <parameter name="driverName" value="chrome" />
    <classes>
    <class name="com.dbyl.tests.Case1" />
    <class name="com.dbyl.tests.JDaddress" />
    <class name="com.dbyl.tests.UseCookieLogin" />
    <class name="com.dbyl.tests.MapTest" />
    <class name="com.dbyl.tests.loginTest" />
    </classes>
    </test> <!-- Test -->
    </suite> <!-- Suite -->

    参数怎么使用?

         这要在case里添加@Parameters 的annotations

         如果有多个parameter,可以一次传入

    package com.dbyl.tests;

    import org.testng.annotations.Parameters;
    import org.testng.annotations.Test;
    /**
    * This Test for verify Parameter annotation
    *
    @author Young
    *
    */
    public class passParameter {

    /**
    *
    *
    @param parameter1
    *
    @param parameter2
    */
    @Parameters({
    "parameter1","parameter2"})
    @Test(groups
    ="parameter")
    public void parameter(String parameter1,int parameter2 )
    {
    System.out.println(
    "parameter1 is "+parameter1 );
    System.out.println(
    "parameter2 is "+parameter2 );
    }
    }

    其中testng的配置文件为:

       

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="Suite" parallel="classes" thread-count="5">
    <test verbose="2" preserve-order="true" name="TestDebug">
    <parameter name="parameter1" value="parameter1" />
    <parameter name="parameter2" value="123" />
    <classes>
    <class name="com.dbyl.tests.passParameter" />
    <class name="com.dbyl.tests.TestngExample" />
    </classes>
    </test> <!-- Test -->
    </suite> <!-- Suite -->

    这里使用两个parameter标签,传递两个参数

    执行结果如下:     

    [TestNG] Running:
    C:\Users\workspace\Demo\Parametertestng.xml

    [TestRunner] Starting executor for test TestDebug with time out:2147483647 milliseconds.
    parameter1 is parameter1
    parameter2 is 123

    接下来尝试从ant命令行执行test suite

    首先在 build配置文件加入:

    <taskdef resource="testngtasks" classpath="testng.jar"/>

    在target执行文件设置testng.xml路径

    <xmlfileset dir="${basedir}" includes="Parametertestng.xml"/>

     

    详细:

     

     1 <?xml version="1.0"?>
    2 <project name="Demo" default="run" basedir=".">
    3 <echo message="Start selenium Grid" />
    4 <echo message="import libs" />
    5 <path id="run.classpath">
    6 <fileset dir="${basedir}">
    7 <include name="lib/poi/*.jar" />
    8 <include name="lib/poi/lib/*.jar" />
    9 <include name="lib/testng.jar" />
    10 <include name="lib/sikuli-script.jar" />
    11 <include name="lib/*.jar" />
    12 </fileset>
    13 <fileset dir="${basedir}/lib/selenium">
    14 <include name="selenium-java-2.45.0.jar" />
    15 <include name="libs/*.jar" />
    16 </fileset>
    17 </path>
    18 <taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="run.classpath" />
    19 <target name="clean">
    20 <delete dir="build"/>
    21 </target>
    22 <target name="compile" depends="clean">
    23 <echo message="mkdir"/>
    24 <mkdir dir="build/classes"/>
    25 <javac srcdir="src" destdir="build/classes" debug="on" encoding="UTF-8">
    26 <classpath refid="run.classpath"/>
    27 </javac>
    28 </target>
    29 <path id="runpath">
    30 <path refid="run.classpath"/>
    31 <pathelement location="build/classes"/>
    32 </path>
    33 <target name="run" depends="compile">
    34 <testng classpathref="runpath" outputDir="test-output"
    35 haltonfailure="true"
    36 useDefaultListeners="false"
    37 listeners="org.uncommons.reportng.HTMLReporter,org.testng.reporters.FailedReporter" >
    38 <xmlfileset dir="${basedir}" includes="testng.xml"/>
    39 <jvmarg value="-Dfile.encoding=UTF-8" />
    40 <sysproperty key="org.uncommons.reportng.title" value="AutoMation TestReport" />
    41 </testng>
    42 </target>
    43 <target name="runTestng" depends="compile">
    44 <testng classpathref="runpath" outputDir="test-output"
    45 haltonfailure="true"
    46 useDefaultListeners="false"
    47 listeners="org.uncommons.reportng.HTMLReporter,org.testng.reporters.FailedReporter" >
    48 <xmlfileset dir="${basedir}" includes="Parametertestng.xml"/>
    49 <jvmarg value="-Dfile.encoding=UTF-8" />
    50 <sysproperty key="org.uncommons.reportng.title" value="AutoMation TestReport" />
    51 </testng>
    52 </target>
    53 </project>
    View Code

    接下在在命令行执行: ant runTestng

    运行结果:

    C:\Users\workspace\Demo>ant runTestng
    Buildfile: C:\Users\workspace\Demo\build.xml
    [echo] Start selenium Grid
    [echo] import libs

    clean:
    [delete] Deleting directory C:\Users\Young\workspace\Demo\build

    compile:
    [echo] mkdir
    [mkdir] Created dir: C:\Users\Young\workspace\Demo\build\classes
    [javac] C:\Users\Young\workspace\Demo\build.xml:25: warning: 'includeantrunt
    ime' was not set, defaulting to build.sysclasspath=last; set to false for repeat
    able builds
    [javac] Compiling 21 source files to C:\Users\Young\workspace\Demo\build\cla
    sses

    runTestng:
    [testng] [TestNG] Running:
    [testng] C:\Users\workspace\Demo\Parametertestng.xml
    [testng]
    [testng] [TestRunner] Starting executor for test TestDebug with time out:2147
    483647 milliseconds.
    [testng] parameter1 is parameter1
    [testng] parameter2 is 123
    [testng] This is beforeClass method .The Value of a is: 1
    [testng] This is beforeMethod method. The Value of a is: 2
    [testng] This is Test method1 .The Value of a is: 3
    [testng] This is AfterMethod Method .The Value of a is: 6
    [testng] This is beforeMethod method. The Value of a is: 2
    [testng] This is Test method2 .The Value of a is: 4
    [testng] This is AfterMethod Method .The Value of a is: 6
    [testng] This is AfterClass Method .The Value of a is: 5
    [testng]
    [testng] ===============================================
    [testng] Suite
    [testng] Total tests run: 3, Failures: 0, Skips: 0
    [testng] ===============================================
    [testng]
    [testng] [TestNG] Time taken by [FailedReporter passed=3 failed=0 skipped=0]:
    0 ms
    [testng] [TestNG] Time taken by org.uncommons.reportng.HTMLReporter@65fe58e0:
    120 ms

    BUILD SUCCESSFUL
    Total time: 5 seconds

     


    转载请注明本文地址: testng教程之testng.xml的配置和使用,以及参数传递
    展开全文
  • eclipse安装testNG教程

    2018-12-20 10:20:45
    作为一个经典的入门例子,这里展示如何开始使用TestNG单元测试框架。 使用的工具 : TestNG 6.8.7 Maven 3 Eclipse IDE TestNG下载并安装 从这里http://testng.org/doc/download.html下载当前版本的TestNG,...
  • TestNG中的监听 1.使用监听的目的: Testng虽然提供了不少强大的功能和灵活的选项,但不能解决所有的问题,使用监听器就是用来定制额外的功能以满足我们的需求的; 2.监听器具体实现: 监听器实际上是一些预...
  • TestNG教程(IDEA)

    2021-06-16 15:03:35
    环境配置: File->new->project->maven项目 创建完成后,在pom中添加配置文件 配置文件如下: org.testng testng 7.0.0 test com.beust jcommander 1.81 添加完成后,在hanhan_testng->src->main->java下创建一个...
  • 1.TestNG是什么? TestNG是一个测试框架,其灵感来自JUnit和NUnit,但引入了一些新的功能,使其功能更强大,使用更方便。 TestNG是一个开源自动化测试框架;TestNG表示下一代(Next Generation的首字母)。 TestNG...
  • testNg教程

    2015-07-19 09:53:51
    1、http://www.cnblogs.com/TankXiao/p/3888070.html#introduce 2、不是很好的教程: http://www.yiibai.com/html/testng/2013/0913291.html
  • TestNG使用教程详解

    2020-12-09 21:14:37
    TestNG是Java中的一个测试框架, 类似于JUnit 和NUnit, 功能都差不多, 只是功能更加强大,使用也更方便。 详细使用说明请参考官方链接。TestNG是一个测试框架,其灵感来自JUnit和NUnit,但引入了一些新的功能,使其...
  • TestNGTestNG使用教程详解

    万次阅读 多人点赞 2018-10-23 10:53:06
    一、TestNG介绍 TestNG是Java中的一个测试框架, 类似于JUnit 和NUnit, 功能都差不多, 只是功能更加强大,使用也更方便。 二、TestNG安装(基于eclipse+maven) 工程的pom.xml中需要添加如下内容: &amp;amp;...
  • 1.异常测试 package com.testngdemo; import org.testng.annotations.Test; public class test { @Test(expectedExceptions = ArithmeticException.class ) public void divisionWithException() { int ...
  • TestNG使用教程

    千次阅读 2018-12-28 11:32:33
    JUnit 4和TestNG都是Java中非常受欢迎的单元测试框架。两种框架在功能上看起来非常相似。 哪一个更好? 在Java项目中应该使用哪个单元测试框架?下面表中概括了JUnit 4和TestNG之间的功能比较。如下图所示 二....
  • TestNG入门教程-1-TestNG简介

    万次阅读 多人点赞 2017-11-06 22:02:47
    说明:由于该系列是好友之邀,优先提供给好友的自媒体账号发布Testng系列文章,所以可能大家会提前看过接下来的这些文章内容。  这个系列文章,我们来系统地学习下Java编程语言中,比较流行的单元测试框架TestNG...
  • org.testng.annotations.Listeners ; public class TestCaseRetry implements IRetryAnalyzer{   // 设置当前执行失败的次数   private static int retryCount = 1;   // 设置最大失败...
  • testng链接:https://www.jianshu.com/p/8b382ea49021 javadoc之testng:javadoc ...当套件中的测试执行失败时,TestNG都会创建一个名为testng-failed.xml的文件,该XML文件包含运行失败的方法的信息,允许您快
  • junit教程与testng教程

    2019-07-01 21:00:40
    https://www.yiibai.com/junit/junit-assertions.html https://www.yiibai.com/testng
  • TestNG 入门教程

    千次阅读 2018-03-26 12:15:30
    TestNG 入门教程国庆7天假期,大部分朋友都出去旅游了,微信圈里全是晒旅游的照片, 东南亚游,欧洲游呀,真是羡慕呀。 悲惨的我只去了上海野生动物园, 在家休息,利用这段假期,把之前学过的东西都总结下。 我前...
  • TestNG 是自动化测试框架,比Junit更强大,可用于单元测试,功能测试,端到端测试等,下面我们就介绍一下如何基于IntelliJ IDEA 创建TestNG test? 打开IntelliJ IDEA -> Create New Project -> Next -> Next -&...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,430
精华内容 972
关键字:

testng教程