Friday, October 26, 2007

No Java 6 in Leopard - I quit

In the past, I thought I would buy a Mac Book Pro to replace my old 3 years Dell Inspiron. That time I heard "MacOS is a comprehensive Java development environment". Also in the point of view of an end user, GUI in MacOS it's more beautiful than the one in Linux and it has many more popular (and better) applications than Linux (You must know that when I used Ubuntu, even I could listen to the music, Skype's voice feature stopped to work without any errors)

But now there is no Java 6 in Leopard (MacOS X 10.5), so I quit. I think you too if you're a Java developer.

Thursday, October 25, 2007

Stubs, Fakes, and Mocks

Funny descriptions about stubs, fakes and mocks, they help me easily to distinguish stubs, fakes and mocks.

Stubs - Looks like a duck but it's not a duck
Fakes - Looks like a duck, walks like a duck but it's not a real duck
Mocks - It's a mechanical duck

TestNG's @DataProvider versus JUnit 4's Parameterized

In "Test Driven - Practical TDD and Acceptance TDD for Java Developers", Koskela used JUnit 4 as unit testing framework but I want to use TestNG so I need to "translate" from JUnit 4 to TestNG. I think it's a good opportunity to know about both of these unit testing frameworks.

In chapter 4, Koskela described about test patterns and one of them is Parameterized Test. To apply this pattern, we need to follow the rule to write the test class as below:

+ The test class must be annotated by @RunWith(Parameterized.class),
+ Supply a static method, is annotated by @Parameters and returns a Collection<Object[]> or its subclass,
+ And we need to write a constructor which has parameters for expected value and input values.

Example:
@RunWith(Parameterized.class)
public class ParameterizedTest {
// Provide parameterized data
@Parameters
public static Collection<Object[]> parameters() {
Object[][] data = new Object[][] {
{ 0, 0, 0 }, { 1, 1, 0 },
{ 2, 1, 1 }, { 3, 2, 1 },
{ 4, 3, 1 }, { 5, 5, 0 },
{ 6, 8, -2 } };
return Arrays.asList(data);
}

public int expected, input1, input2;

// Data is bound through constructor
public ParameterizedTest(int expected, int input1,
int input2) {
this.expected = expected;
this.input1 = input1;
this.input2 = input2;
}

//Test method invoked once for each data set
@Test
public void executeParameterizedTest() throws Exception {
assertEquals(expected, new Calculator().add(input1,
input2));
}
}

It looks very complicated, huh? Now, I will "convert" it to TestNG.

After awhile, I found that TestNG's @DataProvider can do the same thing. And here is the rule to write test class with TestNG following Parameterized Test pattern:

+ Supply a method (don't need to be static) is annotated by @DataProvider(name = "dataProviderName") and returns Object[][],
+ Test method is annotated by @Test(dataProvider = "dataProviderName") and has parameters as same as the Object[]'s elements in data is supplied from data provider

The above source code after was "converted":
public class ParameterizedTest {
@DataProvider(name = "data")
public Object[][] parameters() {
return new Object[][] {
{ 0, 0, 0 }, { 1, 1, 0 },
{ 2, 1, 1 }, { 3, 2, 1 },
{ 4, 3, 1 }, { 5, 5, 0 },
{ 6, 8, -2 } };
}

@Test(dataProvider = "data")
public void executeParameterizedTest(int expected,
int input1,
int input2)
throws Exception {
assert (expected == new Calculator().add(input1,
input2));
}
}

The test class is written with TestNG is much simpler also you can have many data providers as you want. And what will happen if you want to test the Calculator for substraction? If you use JUnit 4 as unit testing framework, seems you need to write another test class.

Wednesday, October 24, 2007

TDD - The hardest thing

These days I spend my spare time to read "Test Driven - Practical TDD and Acceptance TDD for Java Developers". I've just finished chapter 2 and started to bump in chapter 3 but I found out that "Test Driven" is an interesting book (more interesting than "Agile Java: Crafting Code with Test-Driven Development")

In chapter 2 and 3, the author teaches me how to start TDD (test-driven development) with a template parser step by step. IMO, the hardest thing when we start TDD is find out the tests from the requirements or user stories. In simple application, it's easy to find them out. But in more complicated one, it's very hard to find.

In template parser application, I can easy to find out some tests:

+ Test for empty template
+ Test for replacing a variable in the template with its value
+ Test for replacing multiple variables with their values respectively

but in case of an employee management application, how can I find the tests? This question is not easy to answer.

Update: Fix typo

Wednesday, October 17, 2007

Tip: How to get an IntelliJ IDEA license for free

A few minutes ago I received an email from JetBrains, and do you know what did it say? It said "Hey guy, it's an IntelliJ IDEA license, it's for you, and it's FREE", just kidding :-) Here is a part of email from JetBrains

Hello,

We appreciate your participation in development of IntelliJ IDEA 7.0, and we hope you will continue using IntelliJ IDEA with even more pleasure with the attached below personal license.

Be prepared to receive another gift from JetBrains this week :-)

-The JetBrains Team-

I greatly appreciate JetBrains' kindness when they give me this present, a 249$ present. But more than the cost, actually they give me a FREE super weapon to work with, to play with and to have fun with.

And now it's the tip: Please download, use and report the bugs you would found in EAP versions of IntelliJ IDEA, you will have a chance to get an IntelliJ IDEA license for free.

Again, thanks JetBrains. Now it's the time to develop with "FREE" pleasure ;-)

Update: After reading the email more carefully, I found that JetBrains will have another gift for me this week. Waiting for another big surprise... :-)

Update: JetBrains gave me a big surprise one more time, I've just received an Amazon.com Gift Certificate. Again, I want to say thanks to JetBrains, you gave me surprise time after time :-)

Tuesday, October 16, 2007

IntelliJ IDEA 7.0 reaches to final


Early this morning JetBrains released IntelliJ IDEA 7.0. This new version provides many new and interesting features and also it supplies many improvement (include performance) to support the developers to develop the software with pleasure. You can find the complete list of new features here. And the news about it also was published on several sites: here, here and here.

IMO, these features are the ones I love:

+ Support for Spring
+ Support for Hibernate
+ Integration between Spring and Hibernate
+ Improvement in Change View
+ Support for Groovy

Congratulations, JetBrains! It's the time to develop with more pleasure :-)

Monday, October 15, 2007

Dilbert & IntelliJ

Check it out. It's really funny :-)


(Thanks Alex for providing it)