Friday, December 23, 2011

Better testing with Testng

Most of the programmers busy with writing code and forget the importance of having tested the implementations then and there.When you start writing tests you should select the best suitable framework for your job or else you will make things worse. There are few different tests such as
  • Unit test : You have a clear narrow and well defined scope to check a single point of large story/ contract
  • Integration test : In this you will be checking inter operation with more than one sub systems and may expand across system boundaries.
  • Smoke test/ sanity tests: This is a basic integration test for a product to verify system perform its basic functionality as expected
  • Regression test : Test to verify a fixed bug is actually fixed and it will not encounter again
  • Acceptance test : This is also a form of integration test which carried out to verify a use case or a user story
Out of these tests JUnit is adequate to perform Unit tests but for integration tests it has some limitations. If you have some complex dependencies between modules or states such as a sever needed to be started with deployed artiface before all the tests execute or establish a database connection with some preconditions you will find hard time if you choose JUnit .One key important thing you need to keep in mind is “JUnit instantiate class before it runs each and every test method”.
There are lots of comparisons between JUnit and Testng [1][2].When you go through them you will realize how Testng becomes your trusted companion for tests such as integration tests.Testng provides you annotations to control things better and a very cleaner way.Not only that you have custom testng.xml file which enables to customize things to accomplish lots of things as desirable.
If you wish to migrate to Testng there are lots of resources available to learn about Testng.But i advice do not try to convert JUnit tests directly but rather modify them to inherit elegance of Testng :) .
  • Add Testng as a maven dependency

  • Annotations available [3]
@BeforeSuite: The annotated method will be run before all tests in this suite have run.
@AfterSuite: The annotated method will be run after all tests in this suite have run.
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the <test> tag is run.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the <test> tag have run.
@BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
@AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
@BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
@AfterClass: The annotated method will be run after all the test methods in the current class have been run.
@BeforeMethod: The annotated method will be run before each test method.
@AfterMethod: The annotated method will be run after each test method.
  • How to handle Expected exceptions

@Test(expectedExceptions = ExpectedException.class)
  public void expectedExceptionTester() {
The above method should throw the expected exception otherwise it should fail.

Sunday, December 4, 2011

Tweaks for your Thinkpad with Linux

I got a thinkpad T520 recently which i would say really cool due to its form factor and also due to some “serious” configuration it had out of box :) .But if you happened to install a Linux distro things would not be smooth.There are less problems if you use a recent distro which has the knowledge of what “Sandybridge” is capable of [1].I am using LinuxMint 12 so these tweaks valid for Ubuntu 11.10 as well (and 11.04 too.)
 Reducing the power consumption
There has been a problem with the excess power usage which resulted eating the juice in your battery hungrily.
Following steps were referred from the links [2][3] and tested successfully in my laptop.
Install powertop to view how much power your laptop consume.It will show the power consumption when you are running on battery.
sudo apt-get install powertop
1. Open GRUB configuration file:
gksudo gedit /etc/default/grub
(usually looks like this: GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”)
3. Change that line into
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash pcie_aspm=force pcie_aspm=force i915.i915_enable_rc6=1 i915.i915_enable_fbc=1 i915.lvds_downclock=1″
(details about every option can be found on mentioned link)
4. run command to update GRUB configuration:
sudo update-grub
5. restart computer
Now if you check with powertop you can see the reduced power consumption. (According to my results it get reduced from 33W to around 19W.
Next  headache you might have with bluetooth.Since it consumes power you may need to turn it off whenever you do not want it.But it is painful to have it on by default at every startup. You can have it turned off by adding the following entry to .profile file in home folder.
rfkill block bluetooth
To fix the fan problem.
You do not have a dynamic fan configured which speed scale up or down according to the heat and has fixed RPM.It may have noise and also may result in some unwanted power consumption if you in idle or temperature is not high.You can refer this thread where i extracted information for more details.[4].
1. install thinkfan package:
sudo apt-get install thinkfan
2. add kernel module ‘coretemp’ to /etc/modules
sudo sh -c ‘echo coretemp >> /etc/modules’
3. load kernel module ‘coretemp’
sudo modprobe coretemp
4. add the following three sensor entries to /etc/thinkfan.conf just before the temperature levels:
sensor /sys/devices/platform/coretemp.0/temp1_input
sensor /sys/devices/platform/coretemp.0/temp2_input
sensor /sys/devices/platform/coretemp.0/temp3_input
sensor /sys/devices/virtual/hwmon/hwmon0/temp1_input
[ edit the file /etc/thinkfan.conf with your favourite editor, e.g. 'sudo gedit /etc/thinkfan.conf' ]
5. add the following to /etc/modprobe.d/thinkfan.conf: ‘options thinkpad_acpi fan_control=1′
sudo sh -c ‘echo “options thinkpad_acpi fan_control=1″ >> /etc/modprobe.d/thinkfan.conf’
6. reload kernel module ‘thinkpad_acpi’
sudo modprobe -r thinkpad_acpi
sudo modprobe thinkpad_acpi
7. set START=”yes” in /etc/default/thinkfan
[ edit the file /etc/default/thinkfan with your favourite editor, e.g. 'sudo gedit /etc/default/thinkfan' ]
8. start thinkfan:
sudo /etc/init.d/thinkfan start
9. check whether it works
sudo cat /proc/acpi/ibm/fan
if level has a value between 0 and 7, and changes by times, your thinkfan daemon works.

Finger Print Reader.

if you have a fingerprint reader in your T520 you can enable its functionality using fprint. Here is a great tutorial. (I am not a great fan of it.I prefer typing my password than swapping the index finger ;) which is bit productive for me. )

Thursday, December 1, 2011

Hello World

Hi all,I am starting fresh this blog b’cos i am entering a new phase of my life.I have been learning theories for last 24 years a lot.Now it is high time to make some useful things out of it.Life is all about choices.I had to made a couple of them.This is my first weekend after the first two days of my Job @ WSO2.No doubt it is one of the best decisions i made in my life to choose WSO2 as my internship company.Since then the way of learning change drastically.I met lots of people.I specially thank Dr.Srinath Perera who played different roles in my life as a mentor and supervisor.
There are lots of promising things coming up in my life.New technologies, new processes to learn and adopt which i mostly welcome to my life to embrace new challenges.
I am sure this blog will be the public “source code” of my life.If you believe if there is something useful please adopt, modify and redistribute.