TestNG Mockito Example Stubbing Void Methods

In this post we will learn about using TestNG and Mockito together. We will also learn about stubbing void methods with Mockito. Mockito library enables mocks creation, verification and stubbing. In simple terms, mock objects comes handy in situations like when you are testing a class [A] which depends on another class [B]. To test…

Continue reading

TestNG @DataProvider Example

In this post we will learn about TestNG @DataProvider annotation to parameterize your tests in order to write data-driven tests. In data-driven testing, we run the same tests multiple times but with different sets of data which we pass into test methods using parameters. Let’s take a simple Calculator example: Above class have only one…

Continue reading

TestNG @Parameters Example

In this post we will learn about how to parameterize your TestNG tests using TestNG @Parameters annotation which is used to pass simple primitive parameters from configuration file to test methods. These parameters are defined in suite [testng.xml] file. In TestNG, there are primarily two popular ways to pass parameters to your tests in order…

Continue reading

TestNG dependsOnGroups Example

In this post we will see TestNG groups dependency example showing a test depending on groups of tests methods using @Test annotation’s dependsOnGroups and alwaysRun attributes. dependsOnGroups : dependsOnGroups attribute on a test method [test1 e.g.] specifies all the groups [group1, group2,..] this test method depends on. It means test1 will start execution only after…

Continue reading

TestNG dependsOnMethods Example

In this post we will see TestNG dependency example between different test methods using @Test annotation’s dependsOnMethods and alwaysRun attributes. A very simple and real life use case [where these attributes can be handy] is user update operations e.g. In order to update a user, it must be created at first place. So while writing…

Continue reading

TesNG expectedExceptions example

In this post we will learn how to use TestNG expectedExceptions feature to test the expected exception your code might throw in certain situations. We can annotate a test method with particular exception information using @Test(expectedExceptions = Exception.class) if we know that the method will throw this kind of exception during execution. Let’s take a…

Continue reading

TestNG timeOut example

In this post we will learn how to configure TestNG Tests to timeout after certain time, using TestNG timeout feature with help of @Test(timeOut = 1000). A @Test is supposed to complete its execution within very short time. In case a @Test is taking unreasonably long-time than expected, it’s something to investigate. In those situations,…

Continue reading

Testng enabled example

In this post we will learn about how to disable or ignore a test using @Test(enabled=false). Occasionally, we want to disable some tests because of some reasons(like a particular api being tested in those tests is changing but we don’t want to stop the complete CI build which apart from this API should be working…

Continue reading

Maven Surefire plugin & TestNG

In this post we will learn about how to execute TestNG tests with Maven using maven-surefire-plugin. This post also goes over explaining TestNG XML configuration file (aka Suite, testng.xml) , it’s purpose, it’s content, it’s location in your project and how to use it for your tests [using Eclipse plugin or Maven]. What is the…

Continue reading