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
40
votes
2 answers

Does TestNG support something like JUnit4's @Rule?

Does TestNG have something like @Rule? I am thinking specifically about: @Rule public TemporaryFolder folder = ... Or even @Rule public MethodRule globalTimeout = new Timeout(20); I am aware that I can manually implement these things using setUp()…
Francisco
  • 3,980
  • 1
  • 23
  • 27
40
votes
9 answers

What is the difference between BeforeTest and BeforeMethod in TestNG

Both annotations runs before the @test in testNG then what is the difference between two of them.
Sameer Dev
  • 401
  • 1
  • 4
  • 4
40
votes
4 answers

TestNG unit test not working after annotating service to test with @Retention, @Transactional, @Inherited

I am testing a business service with TestNG, mockito unit tests in spring boot application. Application is multi-module spring boot project.And I am writing unit tests for business module. I have added following dependencies related testing in…
Prashant Shilimkar
  • 8,402
  • 13
  • 54
  • 89
40
votes
14 answers

How to run TestNG from command line

How exactly do I run a .java TestNG project from a command line? I have read through the TestNG documentation, and tried the following to no avail: C:\projectfred> java org.testng.TestNG testng.xml ... with the following testng.xml file in my…
Fuzzy Analysis
  • 3,168
  • 2
  • 42
  • 66
39
votes
7 answers

TestNG: How to test for mandatory exceptions?

I'd like to write a TestNG test to make sure an exception is thrown under a specific condition, and fail the test if the exception is not thrown. Is there an easy way to do this without having to create an extra boolean variable? A related blog post…
Christopher Parker
  • 4,541
  • 2
  • 28
  • 33
38
votes
13 answers

element not interactable exception in selenium web automation

In the below code i cannot send password keys in the password field, i tried clicking the field, clearing the field and sending the keys. But now working in any of the method. But its working if i debug and test public class TestMail { …
ragesh-ragav 1993
  • 515
  • 1
  • 5
  • 11
36
votes
5 answers

java.lang.IllegalStateException: missing behavior definition for the preceding method call getMessage("title")

I'm using EasyMock(version 2.4) and TestNG for writing UnitTest. I have a following scenario and I cannot change the way class hierarchy is defined. I'm testing ClassB which is extending ClassA. ClassB look like this public class ClassB extends…
user362199
  • 361
  • 1
  • 3
  • 3
36
votes
8 answers

TestNG: How can I run same test case multiple times?

I want to run a test case multiple times. Is that configurable in the testng.xml? If I add a loop in the test method, then the results of each run will not be affected in the testng report.
Feixiong Liu
  • 443
  • 1
  • 7
  • 14
35
votes
3 answers

Benefits of Maven FailSafe Plugin

I read Maven Failsafe plugin is designed specifically to run integration tests. Currently I'm working on a multi-module project and integration tests are in its own separate module, written in TestNg and run using Surefire plugin. We don't have…
35
votes
31 answers

TestNG ERROR Cannot find class in classpath

I'm trying to run testng via command line and I have following things in classpath: testng jar, jar of compiled test case file, and other required jars. testng.xml points to appropriate class in the hierarchy. Testng doesn't run instead it…
paragm
  • 355
  • 1
  • 3
  • 6
35
votes
5 answers

How do I get the name of the test method that was run in a testng tear down method?

Basically, I have a teardown method that I want to log to the console which test was just run. How would I go about getting that string? I can get the class name, but I want the actual method that was just executed. public class TestSomething { …
Zee Spencer
  • 3,460
  • 6
  • 29
  • 31
35
votes
34 answers

Error: org.testng.TestNGException: Cannot find class in classpath: EmpClass

When i'm trying to run the test suite, am getting this exception. We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then also am getting the same exception. Please…
user2991323
  • 351
  • 1
  • 3
  • 4
34
votes
5 answers

TestNg's @BeforeTest on base class only happening once per fixture

I'm trying to use @BeforeTest to get code to ... run once before every test. This is my code: public class TestBase { @BeforeTest public void before() { System.out.println("BeforeTest"); } } public class TestClass extends…
ripper234
  • 222,824
  • 274
  • 634
  • 905
34
votes
3 answers

How to make Jenkins run Selenium WebDriver/TestNG/Java tests automatically on deploy and what has Maven to do with all this?

I've been researching this for a good few hours now, but I've only found pieces of the big picture. Everywhere they are assuming that the reader already has a part of the system set up. I think it will be useful to have a big picture description of…
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180
34
votes
1 answer

Maven is automatically skipping tests

How come that Maven is skipping all of my tests by default?I have a pom.xml with few profiles and I am not able to run my tests through neither of them. One of my profiles looks like jsf-test
Petr Mensik
  • 26,874
  • 17
  • 90
  • 115