Friday 23 October 2015

WebServer Vs Application Server

1. Application Server supports distributed transaction and EJB. While Web Server only supports Servlets and JSP.
2. Application Server can contain web server in them. most of App server e.g. JBoss or WAS has Servlet and JSP container.
3. Though its not limited to Application Server but they used to provide services like Connection pooling, Transaction management, messaging, clustering, load balancing and persistence. Now Apache tomcat also provides connection pooling.
4. In terms of logical difference between web server and application server. web server is supposed to provide http protocol level service while application server provides support to web service and expose business level service e.g. EJB.
5. Application server are more heavy than web server in terms of resource utilization.

Read more: http://javarevisited.blogspot.com/2012/05/5-difference-between-application-server.html#ixzz3pSqJsgKx

Sunday 30 August 2015

DesiredCapability For Cloud Environment SauceLabs Vs BrowserStack

Additional Keys Are Supported For Setting Desired Capabilities W.R.T execution on cloud environment:

1. Account Name: username=<AccountName>
2. AccessKey : accessKey=<AccessKey>

Example:
/*Below snippet does belong to C# conventions*/
private void setRemoteWebDriverForCloudSauceLabs()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability(CapabilityType.BrowserName, this.browser);
            desiredCapabilities.SetCapability(CapabilityType.Version, this.version);
            desiredCapabilities.SetCapability(CapabilityType.Platform, this.platform);
            desiredCapabilities.SetCapability("username", this.userName);
            desiredCapabilities.SetCapability("accessKey", this.accessKey);
            desiredCapabilities.SetCapability("name", this.executedFrom + " - " + this.jobName + " - " + this.buildNumber + " - " + TestContext.CurrentContext.Test.Name);
            Uri commandExecutorUri = new Uri("http://ondemand.saucelabs.com/wd/hub");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

The same url for saucelabs connection can also contain username and accesskey. For example:
Uri commandExecutorUri = new Uri("http://<username>:<accessKey>@ondemand.saucelabs.com:80/wd/hub");

/*For BrowserStack*/

private void setRemoteWebDriverForCloudBrowserstack()
        {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.SetCapability("browser", this.browser);
            desiredCapabilities.SetCapability("browser_version", this.browser_version);
            desiredCapabilities.SetCapability("os", this.os);
            desiredCapabilities.SetCapability("os_version", this.os_version);
            desiredCapabilities.SetCapability("browserstack.user", this.browserstack_user);
            desiredCapabilities.SetCapability("browserstack.key", this.browserstack_key);
            Uri commandExecutorUri = new Uri("http://hub.browserstack.com/wd/hub/");
            this.driver = new RemoteWebDriver(commandExecutorUri, desiredCapabilities);
        }

How to get list of desiredcapabilities:
SauceLabs: Set Environment Using Utility Given At PlatformConfigurator
1. PlatformConfigurator: https://docs.saucelabs.com/reference/platforms-configurator

 

Thursday 23 April 2015

Unit testing best practices

Unit testing is not about finding bugs
Tips for writing great unit tests
Test only one code unit at a time
Don’t make unnecessary assertions
Make each test independent to all the others
Mock out all external services and state
Don’t unit-test configuration settings
Name your unit tests clearly and consistently
Write tests for methods that have the fewest dependencies first, and work your way up
All methods, regardless of visibility, should have appropriate unit tests
Aim for each unit test method to perform exactly one assertion
Create unit tests that target exceptions
Use the most appropriate assertion methods.
Put assertion parameters in the proper order
Ensure that test code is separated from production code
Do not print anything out in unit tests
Do not use static members in a test class
Do not write your own catch blocks that exist only to fail a test
Do not rely on indirect testing
Integrate Testcases with build script
Do not skip unit tests
Capture results using the XML formatter
Details: http://howtodoinjava.com/2012/11/05/unit-testing-best-practices-junit-reference-guide/