How Test Runners interacting with main method

0 votes
Hi ,

In my View Static void main() -- is the starting point for execution. but test runners dont have  main() method. how execution is happening .
Aug 23, 2020 in Selenium by Sri
• 3,190 points
3,020 views

1 answer to this question.

0 votes

 As main() method is needed to run the Java program and while writing tests in TestNg we don't use main() method,we use Annotations instead.

Annotations in TestNG are lines of code that can control how the method below them will be executed. So, in short you don't need to write main() method, TestNg do that by itself.

You can refer code at the end in Annotations documentation to get the idea how it happens.

Hope it is helpfull!!
Thank you!!

answered Aug 24, 2020 by Niroj
• 82,840 points
Hi @Niroj,

thanks for ur quick response.

1)  Unit test Framework  have annotations , that will take care of what methods to be execute at what time we know this.

2) My Question is, in order to start an execution we need a main() method , without this  execution wont start . this is the entry point .

3) How Unit test Framework   are handling this.

Hello @sri,
Yes, we can execute a java program without a main method by using a static block. 

Static block in Java is a group of statements that gets executed only once when the class is loaded into the memory by Java ClassLoader, It is also known as a static initialization block. 

Example:

class StaticInitializationBlock{   
static{     
System.out.println("class without a main method");     
System.exit(0); 
}
}

Related Questions In Selenium

0 votes
1 answer
0 votes
2 answers

How to test React JS dropdown with Selenium and java?

First of all you need to click ...READ MORE

answered Aug 20, 2019 in Selenium by ghoshPooja
• 140 points
17,769 views
0 votes
1 answer

How can I write test scripts in Selenium with python?

Hey Khushi, writing test scripts in Selenium ...READ MORE

answered May 9, 2019 in Selenium by Anvi
• 14,150 points
904 views
0 votes
1 answer

How to create a test case with TestNG in Selenium?

Hey Deepak, to create a Test Case ...READ MORE

answered May 22, 2019 in Selenium by Abha
• 28,140 points
1,215 views
0 votes
1 answer

How to create a Base Class in Selenium and use it with test scripts?

Hi Donna, you can use following code ...READ MORE

answered Jul 18, 2019 in Selenium by Anvi
• 14,150 points
12,621 views
+2 votes
1 answer

Selenium with C Sharp -- How to perform Explicit Wait method

The explicit wait is used to tell ...READ MORE

answered Dec 23, 2019 in Selenium by Sirajul
• 59,230 points
1,475 views
+1 vote
2 answers

Python with Selenium issue: “Chrome is being controlled by automated test software”

from selenium import webdriver chrome_options = webdriver.ChromeOptions() chrome_options.add_experimental_option("useAutomationExtension", False) chrome_options.add_experimental_option("excludeSwitches",["enable-automation"]) driver ...READ MORE

answered Apr 20, 2020 in Selenium by Manoj
15,910 views
0 votes
1 answer
0 votes
1 answer

How test runner prioritize test classes for execution.

Hello @Sri, TestNG is a Testing framework, that ...READ MORE

answered Aug 24, 2020 in Selenium by Niroj
• 82,840 points
1,147 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP