Test Menu

Performance Testing/Jmeter Interview Questions and Answers

Ques.1. What is Performance Testing?
Ans. Performance testing is non-functional testing in which the application’s performance is evaluated under expected or higher load. It is done before the application is deployed on production to ensure that it doesn’t crash and responds within standard/acceptable time at real load.
Ques.2. What are the different types of Performance Testing techniques?
Ans. The different types of performance testing are-
  • Load Testing – Type of performance testing to measure the application behavior under the expected workload.
  • Stress Testing – Evaluating the application’s behavior under load higher than the application’s threshold or peak load conditions.
  • Endurance Testing – Testing application under prolonged load test, usually used to detect memory leaks in the application.
  • Spike Testing – Evaluating the application’s behavior on a sudden increase in the number of users.
  • Volume Testing – Testing the application with a large amount of data(usually with large records of data in the database).

Ques.3. What all activities are performed during performance testing of any application?
Ans. Activities performed during performance testing-
  1. Performance Test Requirements Gathering & Analysis – In this phase, all the details about the application are gathered from the client and other stakeholders of the application.
  2. Testing Tool Selection – This phase involves the selection of the performance test tools.
  3. Performance Tests Planning – The test planning phase includes planning the whole performance testing process, infrastructure, and environment setup; use case scenarios to be scripted, etc.
  4. Test Script Implementation – In this phase, the performance test scripts are created using the tool selected in the previous phases.
  5. Performance Test Execution – In this phase, the test script is executed for a predefined time specified during the planning phase.
  6. Test Result Analysis – The result analysis phase includes consolidating the test results for determining the different performance attributes of the application and finding the performance bottlenecks.

Ques.4. What is JMeter?
Ans. JMeter is an open-source performance testing tool developed in Java. It can be used for carrying out performance testing of web-based applications, web services(both SOAP and Rest), FTP server, Databases, LDAP server etc.
Ques.5. Why should we choose the JMeter tool for performance testing?
Ans. The advantages of using JMeter tool for performance testing are-
  1. It is free to use with zero licensing costs.
  2. It is open-source, anyone can customize it for their specific use.
  3. It has good online community support and tutorials.
  4. It supports performance testing of a wide variety of applications ranging from websites, web services to FTP and Databases.
  5. It is easy to learn and use.

Ques.6. What are some features of JMeter?
Ans. Some of the features of JMeter are-
  1. JMeter is 100% Java-based. So, it has all the advantages of Java-based applications like portability, extensibility, robustness, etc.
  2. It has a record and playback feature that ensures easy and fast creation of test scripts.
  3. It provides different listeners to capture and analyze the test results in both tabular and graphical format.
  4. It can be used to load test different protocols- HTTP, HTTPS, FTP, LDAP, TCP etc.

Ques.7. What kind of applications can be tested using JMeter?
Ans. The different kinds of applications that can be tested using JMeter are-
  • Websites
  • Web services both – REST and SOAP
  • Databases(JDBC)
  • Shell scripts
  • FTP
  • LDAP
  • TCP
  • SMTP, POP3, IMAP

Ques.8. Explain parameterization in JMeter?
Ans. Parameterization is the process of parameterizing the user input or other test inputs, so as to use different values for different users and loops iterations. Example – an external CSV file can be created with multiple login credentials and then passed to the load test script in order to fetch different credentials for each iteration. 
Ques.9. What is correlation?
Ans. Correlation is the most important aspect of scripting in JMeter. It includes fetching dynamic data from preceding requests/calls and passing them to the subsequent requests as parameters. For example – we can extract the values of session variables from the response of the request with login details and then pass those values to the subsequent requests (thus handling the sessions). 
Ques.10. What is a Test Plan?
Ans. A Test plan in JMeter is a logical container that contains all the test elements which drive the performance test. Some of the different elements in a test plan are – Thread Group, Samplers, Timers, Assertions, Listeners, etc.
Ques.11. What is Workbench?
Ans. A Workbench in JMeter is a temporary area of storage for the test elements. It also contains non-test elements like HTTP Proxy Server, which can be configured to record scripts via browser in JMeter. Any element placed in the workbench doesn’t get saved after with the test plan’s JMX script.
Ques.12. What is a thread group in JMeter?
Ans. A Thread Group is an element of a JMeter test plan that represents a pool of virtual users performing a set of operations.
Ques.13. What is the ramp-up period?
Ans. At the beginning of the load test of an application instead of putting all the users live, we slowly ramp up the number of users in order to study their effect in the application’s performance. In JMeter, the ramp-up period defines the time period within which all the specified users get in running state.
Ques.14. What are samplers in JMeter?
Ans. Samplers are used for sending different types of requests to the server. Some of the commonly used samplers are – HTTP Request, JDBC Request, SOAP-XML Request, JUnit request, TCP Sampler, etc. 
Ques.15. What are Listeners in JMeter? State some of the widely used Listeners?
Ans. Listeners are used for viewing, saving of test results and also help in tabular and graphical analysis of the test results. Some of the widely used Listeners are – Aggregate Report, Aggregate Graph, Graph Results, View Results Tree, etc.
Ques.16. What are the different timers in JMeter?
Ans. Timers are used for halting the test execution of a thread for a certain predefined time. These timers are used for simulating the real user think time. The different types of timers available in JMeter are – Constant Timer, Gaussian Random Timer, Uniform Random Timer, Constant Throughput Timer, Synchronizing Timer, Beanshell timer, BSF Timer, etc.
Ques.17. What is a Rendezvous Point?
Ans. The Rendezvous point in JMeter is used to perform spike testing. It is performed using “Synchronizing Timer” by waiting until the number of active users reaches a certain specified value during the load test.
Ques.18. What are assertions in JMeter? Explain the available assertions in JMeter.
Ans. Assertions in JMeter are used for verification of certain values in the response of Sampler’s requests. The commonly used assertions are – response assertion, size assertion, XML assertion, BeanShell assertion, HTML Assertion, XPath assertion, etc.
Ques.19. What is the use of Configuration elements?
Ans. Configuration elements are used for customizing the sampler requests e.g. CSV Data Set Config can be used for parameterizing the sampler requests with values fetched from the external CSV file.
Ques.20. What are Pre-Processors?
Ans. Pre-processors are the test plan elements that are executed before the sampler request execution. Some commonly used pre-processor in JMeter are BeanShell PreProcessor, HTML Link Parser, HTTP URL Re-writing Modifier, RegEx User Parameters, etc.
Ques.21. What are Post-processors?
Ans. Post-processors are the test plan elements that are executed after the sampler request execution. Generally, post processors are used for fetching some values from the sampler response.
Ques.22. How can we run JMeter in non-GUI mode?
Ans. Command to run JMeter in non-GUI mode-
jmeter -n -t test.jmx -l test.jtl where,
n specifies that JMeter will run in non-GUI mode
-t for test script file
-l for jtl file having each sample’s result
Ques.23. How can we reduce the resource requirement in JMeter?
Ans. To make the best out of the available resources and in general as a practice, the following practices should be incorporated in the tests-
  • Use the non-GUI mode: jmeter -n -t test.jmx -l test.jtl
  • Use as few Listeners as possible; if using the -l flag as above they can all be deleted or disabled.
  • Don’t use “View Results Tree” or “View Results in Table” listeners during the load test, use them only during the scripting phase to debug your scripts.
  • Rather than using lots of similar samplers, use the same sampler in a loop, and use variables (CSV Data Set) to vary the sample. Or perhaps use the Access Log Sampler. [The Include Controller does not help here, as it adds all the test elements in the file to the test plan.]
  • Don’t use JMeter’s functional mode during the load test executions.
  • Use CSV output rather than XML.
  • Only save the data that you need.
  • Use as few Assertions as possible.

Ques.24. What is 90% line in JMeter?
Ans. The aggregate report listener has 90% line as one of the metrics. The Apache JMeter manual describes 90% line as- “90% of the samples took no more than this time”. It is actually the 90 percentile of the response times of the samples –
90 percentile = (90/100)*N+1/2 where N is the number of samples
So, if there are 10 samples then 90%line will be 9.5 or 9. It means the 9th value in the sorted list of samples (sorted according to ascending order of their response times) will be the 90%line value.
Ques.25. What is distributed load testing? How can it be achieved in JMeter?
Ans. Distributed load testing is the process using which multiple systems can be used for simulating the load of a large number of users. The reason for using more than one system for load testing is the limitation of a single system to generate a large number of threads (users). In JMeter, we can do distributed load testing using the master-slave configuration. [For complete steps to perform distributed load testing refer to the post- Distributed load testing in JMeter]

TestNG Interview Questions and Answers

Ques.1. What is TestNG?
Ans. TestNG(NG for Next Generation) is a testing framework that can be integrated with selenium or any other automation tool to provide multiple capabilities like assertions, reporting, parallel test execution, etc.
Ques.2. What are some advantages of TestNG?
Ans. Following are the advantages of TestNG-
  1. TestNG provides different assertions that help in checking the expected and actual results.
  2. It provides parallel execution of test methods.
  3. We can define the dependency of one test method over others in TestNG.
  4. We can assign priority to test methods in Selenium.
  5. It allows grouping of test methods into test groups.
  6. It allows data-driven testing using @DataProvider annotation.
  7. It has inherent support for reporting.
  8. It has support for parameterizing test cases using @Parameters annotation.

Ques.3. How is TestNG different from Selenium WebDriver?
Ans. Selenium is an automation tool using which we can automate web-based applications. In order to add testing capabilities in the Test Automation suites – Selenium is clubbed with TestNG. With TestNG, we can have different features in our automation suite like different types of assertions, reporting, parallel execution, and parameterization, etc.
In short, for doing Automation Testing, Selenium helps with ‘automation’ and TestNG helps with ‘testing’ capabilities.

Ques.4. What is the use of testng.xml file?
Ans. The testng.xml file is used for configuring the whole test suite. In testng.xml file, we can create a test suite, create test groups, mark tests for parallel execution, add listeners, and pass parameters to test scripts. We can also use this testng.xml file for triggering the test suite from the command prompt/terminal or Jenkins.

Ques.5. How can we group test cases like separate test cases for Sanity suite, Regression suite, etc?

Ans. Using groups attribute in TestNG, we can assign the test methods to different groups.
1
2
3
4
5
6
7
8
9
10
11
12
//Test method belonging to sanity suite only
@Test(groups = {"sanitySuite"})
public void testMethod1() {
  //Test logic
}
 
 
//Test method belonging to both sanity and regression suite
@Test(groups = {"sanitySuite", "regressionSuite"})
public void testMethod2() {
  //Test logic
}

Ques.6. How can we exclude a Test method from getting executed via testng.xml file?
Ans. Using the exclude tag in testng.xml file, we can exclude a particular test method from getting executed.
1
2
3
4
5
6
7
8
9
10
11
<suite name="Test Suite" verbose="1">
   <test name="TestName">
      <classes>
         <class name="TestClassName">
            <methods>
               <exclude name="testMethodToBeExcluded"/>
            </methods>
         </class>     
      </classes>
   </test>
</suite>

Ques.7. What are some commonly used TestNG annotations?
Ans. The commonly used TestNG annotations are-
  • @Test – @Test annotation marks a method as a Test method.
  • @BeforeSuite – The annotated method will run only once before all tests in this suite have run.
  • @AfterSuite – The annotated method will run only once after all tests in this suite have run.
  • @BeforeClass – The annotated method will run only once before the first test method in the current class is invoked.
  • @AfterClass – The annotated method will run only once after all the test methods in the current class have been run.
  • @BeforeTest – The annotated method will run before any test method belonging to the classes inside the <test> tag is run.
  • @AfterTest – The annotated method will run after all the test methods belonging to the classes inside the <test> tag have run.
  • @BeforeMethod – The annotated method will run before each test method marked by @Test annotation.
  • @AfterMethod – The annotated method will run after each test method marked by @Test annotation.
  • @DataProvider – The @DataProvider annotation is used to pass test data to the test method. The test method will run as per the number of rows of data passed via the data provider method.

Ques.8. What is the order of execution of the test method based on the different annotations?
Ans. The test methods in TestNG follow the Suite->Test->Class->Method sequence combined with the Before annotions->Test annotations->After annotations sequence. So, the order of execution is-
@BeforeSuite
@BeforeTest
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass
@AfterTest
@AfterSuite

Ques.9. What are some common assertions provided by TestNG?
Ans. Some of the common assertions provided by testNG are-
  1. assertEquals(String actual, String expected, String message) and other overloaded data types in parameter
  2. assertNotEquals(double data1, double data2, String message) and other overloaded data types in parameter
  3. assertFalse(boolean condition, String message)
  4. assertTrue(boolean condition, String message)
  5. assertNotNull(Object object)
  6. fail(boolean condition, String message)
  7. true(String message)

Ques.10. How can we disable or prevent a test case from running?
Ans. By setting the “enabled” attribute as false, we can disable a test method from running.
1
2
3
4
5
6
7
8
9
10
11
12
//In case of a test method
@Test(enabled = false)
public void testMethod1() {
  //Test logic
}
 
 
//In case of test method belonging to a group
@Test(groups = {"NegativeTests"}, enabled = false)
public void testMethod2() {
  //Test logic
}

Ques.11. How can we make one test method dependent on others using TestNG?
Ans. Using dependsOnMethods parameter inside @Test annotation in TestNG we can make one test method run only after the successful execution of the dependent test method.
@Test(dependsOnMethods = { "preTests" })

Ques.12. How can we set the priority of test cases in TestNG?
Ans. We can define the priority of test cases using the “priority” parameter in @Test annotation. The tests with lower priority value will get executed first. Example-
@Test(priority=1)

Ques.13. What is the default priority of test cases in TestNG?
Ans. The default priority of a test when not specified is integer value 0. So, if we have one test case with priority 1 and one without any priority then the test without any priority value will get executed first (as default value will be 0 and tests with lower priority are executed first).
Ques.14. How can we run a Test method multiple times in a loop(without using any data provider)?
Ans. Using invocationCount parameter and setting its value to an integer value, makes the test method to run n number of times in a loop.
1
2
3
4
@Test(invocationCount = 10)
public void invocationCountTest(){
   //Test logic
}

Ques.15. What is threadPoolSize? How can we use it?
Ans. The threadPoolSize attribute specifies the number of threads to be assigned to the test method. This is used in conjunction with invocationCount attribute. The number of threads will get divided with the number of iterations of the test method specified in the invocationCount attribute.
1
2
3
4
@Test(threadPoolSize = 5, invocationCount = 10)
public void threadPoolTest(){
   //Test logic
}

Ques.16. What is the difference between soft assertion and hard assertion in TestNG?
Ans. Soft assertions (SoftAssert) allows us to have multiple assertions within a test method, even when an assertion fails the test method continues with the remaining test execution. The result of all the assertions can be collated at the end using softAssert.assertAll() method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Test
public void softAssertionTest(){
   SoftAssert softAssert= new SoftAssert();
  
   //Assertion failing
   softAssert.fail();
   System.out.println("Failing");
 
   //Assertion passing
   softAssert.assertEquals(1, 1);
   System.out.println("Passing");
 
   //Collates test results and marks them pass or fail
   softAssert.assertAll();
}
Here, even though the first assertion fails still the test will continue with execution and print the message below the second assertion.
Hard assertions on the other hand are the usual assertions provided by TestNG. In case of hard assertion in case of any failure, the test execution stops, preventing the execution of any further steps within the test method.
Ques.17. How to fail a testNG test if it doesn’t get executed within a specified time?
Ans. We can use the timeOut attribute of @Test annotation. The value assigned to this timeOut attribute will act as an upperbound, if test doesn’t get executed within this time frame then it will fail with timeOut exception.
1
2
3
4
5
6
@Test(timeOut = 1000)
public void timeOutTest() throws InterruptedException {
   //Sleep for 2sec so that test will fail
   Thread.sleep(2000);
   System.out.println("Will throw Timeout exception!");
}

Ques.18. How can we skip a test case conditionally?
Ans. Using SkipException, we can conditionally skip a test case. On throwing the skipException, the test method is marked as skipped in the test execution report and any statement after throwing the exception will not get executed.
1
2
3
4
5
6
@Test
public void testMethod(){
  if(conditionToCheckForSkippingTest)
 throw new SkipException("Skipping the test");
  //test logic
}

Ques.19. How can we make sure a test method runs even if the test methods or groups on which it depends fail or get skipped?
Ans. Using “alwaysRun” attribute of @Test annotation, we can make sure the test method will run even if the test methods or groups on which it depends fail or get skipped.
1
2
3
4
5
6
7
8
9
@Test
public void parentTest() {
  Assert.fail("Failed test");
}
 
@Test(dependsOnMethods={"parentTest"}, alwaysRun=true)
public void dependentTest() {
  System.out.println("Running even if parent test failed");
}
Here, even though the parentTest failed, the dependentTest will not get skipped instead it will executed because of “alwaysRun=true”. In case, we remove the “alwaysRun=true” attribute from @Test then the report will show one failure and one skipped test, without trying to run the dependentTest method.
Ques.20. How can we pass the parameter to test script using TestNG?
Ans. Using @Parameter annotation and ‘parameter’ tag in testng.xml we can pass parameters to test scripts.
Sample testng.xml –
1
2
3
4
5
6
7
8
<suite name="sampleTestSuite">
   <test name="sampleTest">  
      <parameter name="sampleParamName" value="sampleParamValue"/>
      <classes>
         <class name="TestFile" />
      </classes>     
   </test>
</suite>

Sample test script-
1
2
3
4
5
6
public class TestFile {
   @Test
   @Parameters("sampleParamName")
   public void parameterTest(String paramValue) {
      System.out.println("Value of sampleParamName is - " + sampleParamName);
   }

Ques.21. How can we create data driven framework using TestNG?
Ans. Using @DataProvider we can create a data-driven framework in which data is passed to the associated test method and multiple iterations of the test run for the different test data values passed from the @DataProvider method. The method annotated with @DataProvider annotation return a 2D array of object.
1
2
3
4
5
6
7
8
9
10
11
12
//Data provider returning 2D array of 3*2 matrix
 @DataProvider(name = "dataProvider1")
   public Object[][] dataProviderMethod1() {
      return new Object[][] {{"ABCD","EFG"}, {"k1","r1"},{"k2","r2"}};
   }
 
   //This method is bound to the above data provider returning 2D array of 3*2 matrix
   //The test case will run 3 times with different set of values
   @Test(dataProvider = "dataProvider1")
   public void sampleTest(String s1, String s2) {
      System.out.println(s1 + " " + s2);
   }

Ques.22. What is the use of @Listener annotation in TestNG?
Ans. TestNG provides us different kinds of listeners using which we can perform some action in case an event has triggered. Usually, testNG listeners are used for configuring reports and logging. One of the most widely used listeners in testNG is ITestListener interface. It has methods like onTestSuccess, onTestFailure, onTestSkipped etc. We need to implement this interface creating a listener class of our own. After that using the @Listener annotation we can use specify that for a particular test class our customized listener class should be used.
1
2
3
4
5
6
7
8
@Listeners(PackageName.CustomizedListenerClassName.class)
 
public class TestClass {
    WebDriver driver= new FirefoxDriver();@Test
    public void testMethod(){
    //test logic
    }
}

Ques.23. What is the use of @Factory annotation in TestNG?
Ans. @Factory annotation helps in the dynamic execution of test cases. Using @Factory annotation we can pass parameters to the whole test class at run time. The parameters passed can be used by one or more test methods of that class.
Example – there are two classes TestClass and the TestFactory class. Because of the @Factory annotation, the test methods in class TestClass will run twice with the data “k1” and “k2”
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public class TestClass{
    private String str;
  
    //Constructor
    public TestClass(String str) {
        this.str = str;
    }
  
    @Test
    public void TestMethod() {
        System.out.println(str);
    }
}
  
public class TestFactory{
    //The test methods in class TestClass will run twice with data "k1" and "k2"
    @Factory
    public Object[] factoryMethod() {
        return new Object[] { new TestClass("K1"), new TestClass("k2") };
    }
}

Ques.24. What is the difference between @Factory and @DataProvider annotation?
Ans. @Factory method creates instances of test class and run all the test methods in that class with a different set of data.
Whereas, @DataProvider is bound to individual test methods and run the specific methods multiple times.
Ques.25. How can we run test cases in parallel using TestNG?
Ans. In order to run the tests in parallel just add these two key-value pairs-
  • parallel=”{methods/tests/classes}”
  • thread-count=”{number of thread you want to run simultaneously}”.
<suite name="TestingTestSuite" parallel="methods" thread-count="5">

SQL Queries For Interview Preparation

1.   SQL Query for Retrieving Tables This query can be run to retrieve the list of tables present in a database where the database is “My_Sc...