Monday, 9 March 2020

Top asked advanced TestNG annotations: Set-1 for SDET/Automation Testing/Developers?




Must know TestNG annotations for Experienced Automation Testers
  • alwaysRun 
If set to true, this test method will always be run even if it depends on a method that failed.

  • dependsOnMethods
The list of methods this method depends on.

  • @test:
Marks a class or a method as part of the test.

Example:
@Test
public void methodone() {

           System.out.println("Methodone");

           // Failing test explicitly

           Assert.fail();

      }

      // alwaysRun attribute will override dependsOnMethods if dependent method is failed or skipped

      @Test(dependsOnMethods = "methodone", alwaysRun=true)

      public void methodtwo() {

           System.out.println("Method two");

      }




















  • Description:    
The description for this method. It is important to give a small information about the test case.


  • Enabled:
Whether methods on this class/method are enabled.
When executing TestNG tests, there are scenarios where you have to disable a particular test or a set of tests from getting executed. For example, where a serious bug exists in a feature due to certain tests belonging to certain scenarios that cannot be executed. As the issue has already been identified we may need to disable the test scenarios from being executed.
Disabling a test in TestNG can be done by setting the enable attribute of the @Test annotation to false. This will disable the test method from being executed as part of the test suite.
Note: If this attribute is set for the Test annotation at class level, all the public methods inside the class will be disabled.

Example:

@Test( description = "Verify Login with valid credentials", enabled=false )
Public void login(){}


  • invocationCount 
The number of times this method should get invoked.

  • threadPoolSize  
The size of the thread pool for this method. The method will be invoked from multiple threads as specified by invocationCount.

Note: this attribute is ignored if invocationCount is not specified

  • timeOut   
The maximum number of milliseconds this test should take.

Earlier we discussed how to run classes, methods, and tests in parallel or in multi-threaded mode. TestNG also provides the flexibility to configure a test method to be run in a multi-threaded environment. This is achieved by configuring it while using the @Test annotation on a method.
AutoTest.java
public class AutoTest
{
    @Test(threadPoolSize = 3, invocationCount = 6, timeOut = 1000)
    public void testMethod()
    {
        Long id = Thread.currentThread().getId();
        System.out.println("Test method executing on thread with id as: " + id);
    }
}
The method is configured to run in multi-threaded mode by using the threadPoolSize attribute along with the Test annotation. The value of the threadPoolSize is set to 3; this configures the test method to be run in three different threads.
The other two attributes, invocationCount and timeOut, configures the test to be invoked a multiple number of times and fail if the execution takes more time.

  •  expectedExceptions      
The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.

public class ExceptionTesting {


    @Test(expected = ArithmeticException.class)
    public void testWithException() {
        int i = 1 / 0;
    }

 


Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122

Entire course content can be found below:  COURSE CONTENTCheck below link for question and answers with code:

Check below for TestNG annotations on @After and @Before:

TestNG@after@before 

Check below link on top Interview preparation:

SQL Query   Cucumber-BDD    Linux Commands    Maven   GIT
 


Tuesday, 3 March 2020

Top 11 interview questions on Exceptions handling in Java for SDET/Developers/Automation Testing?Exception handling in Java

This post is completely on theory, but I will post another one with example for each exception mentioned below:
  • Arithmetic Exception: 
It is thrown when an exceptional condition has occurred in an arithmetic operation.

  • ArrayIndexOutOfBoundException: 

 It is thrown to indicate that an array has been accessed with an illegal index. The index is either negative or greater than or equal to the size of the array.

  • ClassNotFoundException:

 This Exception is triggered when we try to access a class whose definition is not found.

  • FileNotFoundException:

This Exception is thrown when a file is not accessible or does not open. Quite common

  • InterruptedException: 

 It is triggered when a thread is waiting , sleeping , or doing some processing , and it is interrupted.


  • NoSuchMethodException: 

It is thrown when accessing a method which is not found.

  • NullPointerException: 

 This exception is appeared when referring to the members of a null object.

  • NumberFormatException:

 This exception is thrown when a method could not convert a string into a numeric format.

  • StringIndexOutOfBoundsException:

It is thrown by String class methods to indicate that an index is either negative than the size of the string.

  • What is checked and unchecked exception?

1) Checked Exception:
The classes which directly inherit Throwable class except the RuntimeException and Error are called as checked exceptions e.g. IOException, SQLException etc. Those exceptions are checked at compile-time.
2) Unchecked Exception:
The classes which inherit RuntimeException are known as unchecked exceptions e.g. ArithmeticException, ArrayIndexOutOfBoundsException ,NullPointerException etc. 
Unchecked exceptions are not checked at compile-time, but they are checked at runtime.

  • What is Error?

Error is not recoverable e.g. OutOfMemoryError, VirtualMachineError, AssertionError etc.



Learn (API-Microservice)Testing+(CoreJava+UI)-SDET with Self Paced Videos and one LIVE Doubt Session

TRANING VIDEOS AVAILABLE with Live Doubt Session @4500/-(course-1 below,API TRaining Videos With ClassNotes and Coding Set) and 6500/- (API+UI, both course-1 & 2 below) Check Training Page for Course Content or reach out @whatsapp +91-9619094122

Entire course content can be found below:  COURSE CONTENTCheck below link for question and answers with code:
 

All Time Popular Posts

Most Featured Post

𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀?

❓ 𝗦𝘁𝗶𝗹𝗹 𝘀𝘁𝗿𝘂𝗴𝗴𝗹𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 𝗝𝗮𝘃𝗮 𝗰𝗼𝗱𝗶𝗻𝗴 𝗿𝗼𝘂𝗻𝗱𝘀? The issue isn’t your logic—it’s the lack of pattern recogniti...