Questions tagged [testng]

TestNG is a testing framework focused on providing both unit and functional testing abilities in the Java programming language. It supports parallel testing, data providers, dependencies, groups and other features.

TestNG is a testing framework inspired from JUnit and NUnit, but introducing some new functionalities that make it more powerful and easier to use, such as:

  • Annotation support.
  • Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc).
  • Test that your code is multi-thread safe.
  • Flexible test configuration.
  • Support for data-driven testing (with @DataProvider).
  • Support for parameters.
  • Powerful execution model (no more TestSuite).
  • Supported by a variety of tools and plug-ins (Eclipse, IDEA, Maven, etc).
  • Embeds BeanShell for further flexibility.
  • Default JDK functions for run-time and logging (no dependencies).
  • Dependent methods for application server testing.
  • Detailed reports of executed tests.
  • Distributed testing: allows distribution of tests on slave machines.

TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.

References:

8489 questions
19
votes
9 answers

A fatal error has been detected by the Java Runtime Environment. EXCEPTION_ACCESS_VIOLATION

I have java 1.6, maven 2, activeMQ 5.5 and functional tests with testng. When I launch it in Idea then OK, but when I try to launch them with maven from console then process suspends after trying to send message via activeMQ and after some time…
Dmitrii Borovoi
  • 2,814
  • 9
  • 32
  • 50
19
votes
2 answers

TestNG @BeforeMethod method not called when it resides in superclass and a specific group is run

I am trying to use a group to run a subset of tests relevant to what I am working on called "current". The problem is that if I use a superclass to do some setup in a @BeforeMethod, the method runs when I run all tests, but does not when I run with…
Ransom Briggs
  • 3,025
  • 3
  • 32
  • 46
19
votes
7 answers

Getting different results for getStackTrace()[2].getMethodName()

For logging purposes, I created a method logTitle() that prints out the calling method name for our TestNG tests. Sample code is below. @Test public void test1() throws Exception { method1(); } public static void method1() throws Exception { …
Greg
  • 3,861
  • 3
  • 23
  • 58
19
votes
6 answers

Priority in TestNG with multiple classes

I'm facing with the following problem: I created two classes which include @Tests with priority attribute: @Test( priority = 1 ) public void testA1() { System.out.println("testA1"); } @Test( priority = 2 ) public void testA2() { …
peetya
  • 3,578
  • 2
  • 16
  • 30
19
votes
5 answers

TestNG.xml suite to include all packages all files

Just about to implement a test framework with Maven+TestNG+Selenium. How do you declare a suite.xml that tells TestNG to run ALL tests? I've tried all these to no avail:
sibidiba
  • 6,270
  • 7
  • 40
  • 50
18
votes
4 answers

What's the difference between DataProvider and Factory in TestNG?

When to use DataProvider and when to use Factory ?
why
  • 1,275
  • 4
  • 12
  • 23
18
votes
1 answer

What is the actual difference between assertEquals() vs assertTrue() in TestNG?

I'm confusing about both these methods, because both can do the same thing, like below snippet of my code. Using assertEquals() String a = "Hello"; String b = "Hello"; assertEquals(a, b); Using assertTrue() assertTrue(a.equals(b)); Can anyone…
Jainish Kapadia
  • 2,603
  • 5
  • 18
  • 29
18
votes
4 answers

Static Metamodel attributes null when unit testing

I have @Entity classes in an external package that also have static metamodels. In my application's service class, I am using those metamodels and the EntityManager/CriteriaBuilder/CriteriaQuery to retrieve my data. This works fine when running the…
HenryC
  • 359
  • 2
  • 13
18
votes
1 answer

How do you mock a JavaFX toolkit initialization?

[preamble: apologies, there is a lot of code here, and some of it may not be relevant to this question while some code which is necessary to understand the problem may be missing; please comment, and I will edit the question…
fge
  • 119,121
  • 33
  • 254
  • 329
17
votes
10 answers

What do you need from a test harness?

I'm one of the people involved in the Test Anything Protocol (TAP) IETF group (if interested, feel free to join the mailing list). Many programming languages are starting to adopt TAP as their primary testing protocol and they want more from it…
Ovid
  • 11,580
  • 9
  • 46
  • 76
17
votes
5 answers

How to continue execution when Assertion is failed

I am using Selenium RC using Java with eclipse and TestNG framework. I have the following code snippet: assertTrue(selenium.isTextPresent("Please enter Email ID")); assertTrue(selenium.isTextPresent("Please enter Password")); First assertion was…
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
17
votes
6 answers

How can I tell Gradle to use my testng.xml file for Test Classes and Ordering?

I am attempting to have Gradle execute some tests defined using a testng.xml file. My testng.xml file looks like this:
Mike Cornell
  • 5,909
  • 4
  • 29
  • 38
17
votes
5 answers

Can TestNG run multiple suites?

I am testing a web-ui using Selenium and TestNG. I have a test suite with many test classes in it. I have a @BeforeSuite method which also has a @Parameters annotation, this method receives as a parameter the browser in which the Selenium test will…
Eli
  • 181
  • 1
  • 3
  • 10
17
votes
2 answers

How to use Maven Surefire plug-in with different groups for test and integration-test?

I want to use testng with the Surefire plug-in of Maven. The idea is to tag some tests with a group integrationTest and run the plug-in twice: for goal test excluding the group integrationTest and for goal integration-test including the group…
Arne Burmeister
  • 20,046
  • 8
  • 53
  • 94
17
votes
3 answers

Reload or refresh a Spring application context inside a test method?

I need to change the Spring profiles that are active in my applicationContext within a single method of my test class, and to do so I need to run one line of code before refreshing the contest because I am using a ProfileResolver. I have tried the…
David E
  • 888
  • 2
  • 8
  • 13