Showing posts with label Coding Styles. Show all posts
Showing posts with label Coding Styles. Show all posts

Tuesday, August 14, 2012

Things that you should remember when test automating(best practices)


Less Hard-coding
We are always tempted to hardcode things. It make our life easy. But this can make maintaining that code a big issue. I had to change some of the places that I did hardcode due to different reasons.

Dates and times
When working with date and times you might forget that, those things are changing. I did this mistake ones in the testing. I was asked to test the service locking functionality. We can lock a service for a specific time. I just hard-corded the dates and times and did the testing. Soon I realized that, if we are going to use them in the future, test going to fail. You might think that is foolish from me, but believe me we miss those little things while cording.

Use of Constants
If you really need to hardcode something do it through a constant, at the bigging of the code. So if it get changed, it is easy for someone else to find and change it

Do not leave thing behind
When you create any objects for testing and if you have done any configuration changes to the product for testing, make sure you undone them before you leave. Those objects and changes can break other tests by other users. You can use @AfterClass for that purpose.

Avoid Test anti-patterns
Just search for the test anti-patterns and you will find lot of them that you should avoid, or at least try to avoid.

Coverage Vs Stable Product
When we are testing, we normally get blinded by the coverage. But always our goal should be to build a stable product. No matter what is the test coverage if our product is failing, all the hard work is for nothing. This is told to me by our team lead Krishantha ayya.

Good Articles

Monday, August 13, 2012

Beginning the Test Automation



We got this order to freeze our current project and join the test automation project, which was lead by Krishantha Samaraweera. 23 of us were divided in to 2 groups and assigned two of our major products, ESB and GREG. I am in the GREG test automation team. Here we are using a test framework called as 'Clarity'. Clarity was wso2 built testing framework which can be used to test our own products. Clarity is still under development. I will talk more about this framework in one of my future posts.

All the tests that we are writing is submitted as patches to the public jira project 'Test Automation'. Our team lead take a look at that and apply them to the main trunk/branch as we are not having committer rights. I will elaborate more on this jira thing and patch submission in my future posts.

We have to adhere to the standard coding style that is used in wso2. I have posted on this matter earlir in this blog. How to use the style xml to configure eclipse. You can find that post here. We used the remote debugging that is available in the IDE to test or patches. You can find my article on remote debugging here.

This was a nice learning curve for all of us. We went through lot of training sessions and was informed with best practices when testing, which were great additions to our knowledge. And it was a new place I was in 59 branch and now I am in 58 branch. And I must mention that here the TT table is far better than what we had in 59. After all this is temporary, I will return to the 59 after this test automation thing is done.

Tuesday, June 5, 2012

Coding Styles and Eclipse


When we are working in a group it is always important to keep a fix standard or a way of coding through the whole group. This increase the readability and maintainability of the code. In WSO2 we are given a set of coding standards. In order to automate this process, you can configure your IDE to perform some formatting related tasks automatically. In Eclipse, we use Code Templates to configure IDE.

Code Cleanup Template


What is 'Code Cleaning up' ? This refers to the way that eclipse cleanup your code when cleanup command is given. It remove all the unnecessary parts and unstandardized parts according to the configuration given. We are given this configuration through a XML file (https://sites.google.com/a/wso2.com/engineering/Home/eclipsecodeformattingtemplatesforwso2developers/WSO2_Eclipse_Code_Cleanup.xml). This sets below configuration.

  • Change non static accesses to static members using declaring type
  • Change indirect accesses to static members to direct accesses (accesses through subtypes)
  • Convert control statement bodies to block
  • Convert for loops to enhanced for loops
  • Remove unnecessary parentheses
  • Add missing '@Override' annotations
  • Add missing '@Override' annotations to implementations of interface methods
  • Add missing '@Deprecated' annotations
  • Remove unnecessary casts
  • Remove unnecessary '$NON-NLS$' tags
  • Add unimplemented methods
  • Remove trailing white spaces on all lines
  • Correct indentation
If you want you can have your own profile, and even you can export it. You can find how to do it in the following article http://www.ibm.com/developerworks/library/os-eclipse-clean/

Code Formatting Template


This template takes care of, how formatting is happen in the code level. Indentation, Braces, white spaces, comments, etc. are formatted according to the given configuration. Again this formatting template is also given to us in WSO2 as a template (https://sites.google.com/a/wso2.com/engineering/Home/eclipsecodeformattingtemplatesforwso2developers/WSO2_Eclipse_Code_Formatter.xml).

In Order to apply these templates, follow the steps given below.

  1. Window -> Preferences
  2. Java-> Code Style
  3. Select Clean up option in the preference page and point to the WSO2_Eclipse_Code_Cleanup.xml.
  4. Select Formatter option in the preference page and point to the WSO2_Eclipse_Code_Formatter.xml
In order to make our life easy we can use eclipse shortcuts : http://www.a2ztechguide.com/2011/08/eclipse-ide-keyboard-shortcuts-for.html