Headless testing is execution of automated UI based test cases without launching browser. Test scripts are being executed but without initializing browser itself. Headless execution is not useful for functional testing but for automation testing its awesome.
Headless browser execution is faster than real browser:
Headless browser for Unit testing:
People working in Software testing services company are using headless browser execution for Unit test cases to save tremendous amount of time. You can simulate multiple browser versions on the same machine.
When Headless browser is not used:
Headless browser execution is not useful when people want to watch the test script execution.
Example of Headless browsers:
Automation code to initialize the Headless chrome browser using Java/Selenium:
ChromeOptions chromeOptions = new ChromeOptions();
ChromeDriver driver = new ChromeDriver(chromeOptions);
Also, Selenium supports headless testing using its class called HtmlUnitDriver. This class internally uses HtmlUnit headless browser.
Code to initialize HtmlUnitWebDriver with Java script support is as follows: [HtmlUnitDriver allows you to select the version of browser that you would like to run your tests on]
HtmlUnitDriver unitDriver = new HtmlUnitDriver();
Hope this information is very helpful for you.