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
171
votes
23 answers

Error "Source option 5 is no longer supported. Use 6 or later" on Maven compile

I am getting the following error on $ mvn compile: [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Sym360: Compilation failure: Compilation failure: [ERROR] Source option 5 is…
SUPARNA SOMAN
  • 2,311
  • 3
  • 19
  • 35
158
votes
14 answers

IDEA 10.5 Command line is too long

In Maven project when I run test case (on Windows): Error running TestApp.readParameter: Command line is too long. In order to reduce its length classpath file can be used. Would you like to enable classpath file mode for all run configurations of…
qinmiao
  • 5,559
  • 5
  • 36
  • 39
126
votes
12 answers

JUnit vs TestNG

At work we are currently still using JUnit 3 to run our tests. We have been considering switching over to JUnit 4 for new tests being written but I have been keeping an eye on TestNG for a while now. What experiences have you all had with either…
Sam Merrell
  • 2,352
  • 2
  • 16
  • 14
100
votes
16 answers

@BeforeClass and inheritance - order of execution

I have an abstract base class, which I use as a base for my unit tests (TestNG 5.10). In this class, I initialize the whole environment for my tests, setting up database mappings, etc. This abstract class has a method with a @BeforeClass annotation…
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77
88
votes
6 answers

JUnit 4 vs TestNG - Update 2013 - 2014

JUnit 4 and TestNG used to be comparable. What are the pros and cons of the two testing frameworks?
Arian
  • 3,183
  • 5
  • 30
  • 58
84
votes
17 answers

Order of execution of tests in TestNG

How to customize the order of execution of tests in TestNG? For example: public class Test1 { @Test public void test1() { System.out.println("test1"); } @Test public void test2() { System.out.println("test2"); } @Test …
Badri
  • 2,212
  • 3
  • 25
  • 26
70
votes
3 answers

Reading JavaScript variables using Selenium WebDriver

I'm using Selenium WebDriver (Java) and TestNG to do some testing on a website I created. In this website, I also have JavaScript and in some of the functions, it returns values and also outputs values to the browser console through console.log(). I…
FilmiHero
  • 2,306
  • 7
  • 31
  • 46
64
votes
3 answers

Spring Dependency Injection with TestNG

Spring support JUnit quite well on that: With the RunWith and ContextConfiguration annotation, things look very intuitive @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:dao-context.xml") This test will be able…
Phương Nguyễn
  • 8,747
  • 15
  • 62
  • 96
63
votes
1 answer

How to disable entire unit test in TestNG?

This is what I can do in JUnit: import org.junit.*; @Ignore public class FooTest { // } and the entire class will be ignored. How can I do the same in TestNG?
yegor256
  • 102,010
  • 123
  • 446
  • 597
61
votes
2 answers

How can I get complete stacktraces for exceptions thrown in tests when using sbt and testng?

The stacktraces are truncated - e.g. they end with [info] ... Using last or changing traceLevel doesn't help - it simply prints the complete stacktrace of the sbt wrapper. This is testing with testng (also I believe using scalatest and sl4j)
wn-
  • 1,475
  • 1
  • 14
  • 14
55
votes
4 answers

Gradle task check if property is defined

I have a Gradle task that executes a TestNG test suite. I want to be able to pass a flag to the task in order to use a special TestNG XML suite file (or just use the default suite if the flag isn't set). gradle test ... should run the default…
user2506293
  • 805
  • 1
  • 7
  • 13
55
votes
8 answers

Difference between BeforeClass and BeforeTest in TestNG

As we know from official TestNG documentation: @BeforeClass: The annotated method will be run before the first test method in the current class is invoked. @BeforeTest: The annotated method will be run before any test method belonging to the classes…
Prashanth Sams
  • 19,677
  • 20
  • 102
  • 125
53
votes
5 answers

Why are empty collections of different type equal?

What is mechanism below that makes equal different types? import static org.testng.Assert.assertEquals; @Test public void whyThisIsEqual() { assertEquals(new HashSet<>(), new ArrayList<>()); }
Bartek
  • 2,109
  • 6
  • 29
  • 40
47
votes
8 answers

Java unit testing: how to measure memory footprint for method call

Assuming I have a class that does some heavy processing, operating with several collections. What I want to do is to make sure that such operation can't lead to out-of-memory or even better I want to set a threshold of how much memory it can…
Sergey Makarov
  • 2,491
  • 2
  • 19
  • 23
47
votes
12 answers

How to execute JUnit and TestNG tests in same project using maven-surefire-plugin?

Right now I have both type of tests but when I say "mvn test" it only executes TestNG tests and not Junit. I want to execute both one after another. Any Idea ?
ravinikam
  • 3,666
  • 6
  • 28
  • 25
1
2 3
99 100