Skip to main content


Showing posts from September, 2015

How did I start practising BDD?

At the beginning days I have practised TDD (Test Driven Development) with using JUnit, I approached that I should test methods belong to a class. For example:

I have a class with some methods:

public class A{ public void method1(){ } public void method2(){ } }
And then, I wrote some test methods to check the corresponding ones, for example:

public class ATest{ @Test public void testMethod1(){ .... assertTrue(...); ..... assertEquals(...); } @Test public void testMethod2(){ } }
After that, I know that a test method (ex: testMethod1) should just only tests one thing, so I decided to write more methods for each cases. It looks like the following:

@Test public void testMethod1_When_Case1(){ .... assertTrue(...); } @Test public void testMethod1_When_Case2(){ .... assertEquals(...); }
However, it was not a really good approach because it seems that I just focused on test the functionality of the method of the class. With TDD approach, I knew that I should test the…

Adding a default text to the beginning of an text area

I have a text area where I can enter a SQL statement. The text "SELECT TOP 1" is used at the begining of the sql statement as a default prefix that can not be removed.

In order to archive this functionality, I found three options:

1. Use an inputMask and build a pattern for the entered text. We can use the prefix inside the text area:

2. Create an javascript event listener on event "input" and calculate to prevent the prefix is removed

3. Use another html tag like "div"/"span" that contains the prefix and calculate the suitable position

+ Tag "span":
+ Tag "div":

I chose the 3rd approach with tag "div" because it's the most easiest solution and suitable for me at that monment.


Strategy Design Pattern

For example, I have an program with an Animal abstract class and two sub-classes Dog and Bird. I want to add a new behavior for the class Animal, this is "fly".  Now, I face to two approaches to solve this issue:

1. Adding an abstract method "fly" into the class Animal. Then, I force the sub-classes should be implemented this method, something like:

public abstract class Animal{ //bla bla public abstract void fly(); } public class Bird extends Animal{ //bla bla public void fly(){ System.out.println("Fly high"); } } public class Dog extends Animal{ //bla bla public void fly(){ System.out.println("Cant fly"); } }
2. Creating an interfaces with method "fly" inside. The same issue to abstract class, I force the classes these implement this interface should have a method "fly" inside:

public interface Flyable{ public void fly(); } public class Bird implements Flyable{ //bla bla public void fly(){ System.out.println…

AngularJS Fundamentals

1. Single Page Application (SPA)

- Single page application versus  Traditional multi-page

- "Single-Page Applications (SPAs) are Web apps that load a single HTML page and dynamically update that page as the user interacts with the app. SPAs use AJAX and HTML5 to create fluid and responsive Web apps, without constant page reloads. However, this means much of the work happens on the client side, in JavaScript"

- "Web browser JavaScript frameworks, such as AngularJS, Ember.js, ExtJS and React have adopted SPA principles"

2. Directive and Data Binding Expression

<!DOCTYPE html> <html lang="en-US"> <script src=""></script> <body> <div ng-app=""> <p>Name : <input type="text" ng-model="name"&…

AngularJS - Using broadcast or shared service to communicate controllers' data

Either using broadcast approach or shared service is enough to solve the problem about communicating data between two controllers. Using broadcast can update immediately the child controller data when performing an event on parent.

Code example on Codepen :

Build Dynamic Forms in AngularJS Directives

We wanted to build a dynamic form that has some types of elements such as text field, text area, label, date picker, combobox, file uploader, etc. Beside that, the form is dynamic because basing on the provided configuration data, it should render our expected GUI.

We conducted a  research with two options: building our own directives or using a third-party directives.

- Approach 1: using a third-party directives

 + Google keyword: "build dynamic forms directives + angular third party"

 + This idea met our idea: "", but it's not free to use.

 + This 3rd-party was possible:

Schema form hello world app:

- Approach 2: building our own directives

We chose this approach because it looks more simple than using "schema form" 3rd-party and we thought that we can confidently handle it.

Example: | http://codepen.i…

Selenium - tests don't interact with IE

Have you ever faced to a problem that your tests work well on Chrome or Firefox, but don't do anything on Internet Explorer after launching the browser? I have met this issue.

Even when my tests have no problems with IE8 but they do not interact with the browser which is upgraded one - IE11, no clicking, no entering anymore. And I got an exception.

These below maybe are one of the solutions:

1. Make sure the zoom is 100% (press Ctrl + 0)

2. Uncheck Enable Protected Mode, and set lowest security level too.

3. Add your address to trust sites.