Selenium-Java Coding Convention( Java Coding Standard )
1.What is coding standard ?
Set of protocols( guidelines ) and programming style that developer follow during writing code/test script.
2.Benefits of following coding standard ?
1.Code is Easy to Read & Understand
If developer of code follows coding standard (i.e. giving meaning-full name to method or variables ) then code will be easy to read & understand to everyone.
2.Code is Easy to Maintain
If everyone is able to understand code then anyone can do necessary changes in future(easy to change/maintain).Your code should be easy to maintain since it is very rare that original author will be available for lifetime.
3.Code is Easy to Contribute
If more than one developer/automation engineer is working on same project they must follow coding standard since it makes easy to share, contribute & integrate. In case of open-source programming language developers from different part of world makes their contribution & following standards very important in this case.
4.Reflects Experience of Developer
Experience developer or Automation engineer should follow coding standard since it reflects their experience.
3.Java Coding Standard:
1. Coding Standard for Class
Generally Class name should be noun & first letter should be in uppercase. And if class name contains more than one word then every inner word should start with uppercase.
e.g. FileInputStream , FileWritter, etc.
2. Coding Standard for Interface
Generally Interface name should be adjective & first letter should be in uppercase. And if Interface name contains more than one word then every inner word should start with uppercase.
e.g. Comparable , Serializable , etc.
3. Coding Standard for Package
Package name should be in lowercase so that no conflicts should be between class & interface name. Mostly firms/ companies use reversed internet domain name as package name followed by project name /module name.
4. Coding Standard for methods
Generally Method name should be verb or verb-noun & it starts with lower case. And if method name having multiple words then camel casing approach is used.
e.g. print(), sleep(), run() ,getName(), setName() etc.
4.1. Getter Methods should
start with prefix “get”
not take any argument
4.2. Setter Method should
start with prefix “set”
return type should be void
take some argument
5. Coding Standard for Variable
Generally Variable name should be noun & it starts with lower case. And if method variable having multiple words then camel casing approach is used.
e.g. name, mobileNumber etc.
Post a Comment