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
33
votes
1 answer

In Java why this error: 'attribute value must be constant'?

I have some TestNG code, where I am passing a Test annotation parameter called timeOut = TESTNG_TEST_TIMEOUT . @Test(description = "Tests something.", groups = { "regression" }, timeOut = TESTNG_TEST_TIMEOUT, enabled = true) And in my TestBase…
djangofan
  • 28,471
  • 61
  • 196
  • 289
32
votes
2 answers

Does TestNG has runner like SpringJUnit4ClassRunner

When I write tests in JUnit (in Spring context) I usualy do it like this: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:testContext.xml") public class SimpleTest { @Test public void testMethod() { //…
Michał Mech
  • 2,035
  • 4
  • 17
  • 26
32
votes
3 answers

Mockito throw Exception

@Test(expectedExceptions=DataAccessException.class) public void testUpdateSubModuleOrderDateExceptionCheck() { //some code to initialize// UserSubModuleDao userSubModuleDao = mock(UserSubModuleDao.class); …
user2375298
  • 1,001
  • 4
  • 15
  • 28
31
votes
4 answers

TestNG dependsOnMethods from different class

The dependsOnMethods attribute of the @Test annotation works fine when the test to be depended upon is in the same class as that of the test that has this annotation. But it does not work if the to-be-tested method and depended-upon method are in…
brayne
  • 1,355
  • 2
  • 16
  • 27
31
votes
3 answers

How to get entered text from a textbox in Selenium

I enter a value in TextBox or a Combobox, and would like to retrieve the value I have just entered. I see that Selenium Weblement method getText() doesn't retrieve the value, it seems the entered text doesn't get pushed into DOM. Any solutions?
Fazy
  • 573
  • 1
  • 5
  • 16
30
votes
15 answers

TestNG by default disables loading DTD from unsecure Urls

I'm using testng maven and selenium to run my tests, currently I have the following testng.xml file Looks like the problem is with the &listeners and &classes lines, If I replace those lines with the xml content that I have on the referenced files…
msiles
  • 657
  • 3
  • 10
  • 19
30
votes
4 answers

assertEquals, what is actual and what is expected?

I always wondered what exactly is the meaning of actual and expected in assertEquals in libraries like TestNG. If we read the Java Docs we see: public static void assertEquals(... actual, ... expected) Parameters: actual - the actual value …
insumity
  • 5,311
  • 8
  • 36
  • 64
30
votes
6 answers

How to execute one test from large TestNG suite using testng.xml?

I have a TestNG suite with large amount of methods. I execute this suite using wrapper built on top of TestNG runner. All tests in the suite fail except one. What should I write in testng.xml to execute just that one failed test? Obvious solution is…
Sad Developer
  • 1,258
  • 1
  • 12
  • 16
30
votes
6 answers

How to pass java code a parameter from maven for testing

I need to pass on following values … exeEvironment (Test environment) , testGroup (Group in testNG) from Command-Line -> POM -> TestNG -> Test cases. Based on these two posts .... pass a java parameter from maven How to pass parameters to…
Girish
  • 1,981
  • 3
  • 17
  • 18
30
votes
5 answers

JPA-based JUnit Test Best Practices

This is a bit of an odd question, but it has been bothering me for a few months now. I have built a JPA-based web application using Wicket + Hibernate (built with Maven), and want to test the DAO layer directly. I created a specific…
mlaccetti
  • 1,726
  • 2
  • 18
  • 17
30
votes
3 answers

Mixing Hamcrest and TestNG

Has anyone integrated Hamcrest with TestNG so that its matchers can easily be used in TestNG assertions?
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
29
votes
4 answers

Can I run a specific testng test group via maven?

I have several testng test groups, e.g. group1,group2,group3... These are defined in my pom.xml and all get run when I execute "mvn test". What do I need to run to only execute one group without having to modify the groups configured in the…
Tom Eustace
  • 293
  • 1
  • 3
  • 4
28
votes
5 answers

TestNG: More than one @DataProvider for one @Test

I'm using TestNG for Eclipse. Is it possible to give two data providers step by step to the same test-function? I could put both providers in one, but that is not what I want. I need (not like in this example) to generate independently…
Malte Onken
  • 769
  • 1
  • 9
  • 20
27
votes
7 answers

How to disable TestNG test based on a condition

Is there currently a way to disable TestNG test based on a condition I know you can currently disable test as so in TestNG: @Test(enabled=false, group={"blah"}) public void testCurrency(){ ... } I will like to disable the same test based on a…
Afamee
  • 5,160
  • 9
  • 38
  • 43
27
votes
10 answers

Maven Compilation error [package org.testng.annotations does not exist]

I'm pretty new to maven and I want to run my test classes using maven. I have generated the testng.xml and I have created the POM.xml file also. But when you run the mvn install, it generates this error : [package org.testng.annotations does not…
user3060386
  • 271
  • 1
  • 3
  • 5