Introduction to BDD
BDD, Behaviour Driven Development, is a response to TDD by Dan North. I cannot explain better than its creator, and he does explain it here.
Dan North created the first BDD framework ever, JBehave.
But, sadly, it is too late to use BDD in GeoGebra and test the whole system would take ages. I guess the best approach now would be start using BDD for new development while using Bug Driven Development. Bug Driven Development consists on adding the needed specs in order to avoid an already reported bug to reappear.
Installing easyb
First, let install two plug-ins for Eclipse. First, the Groovy plug-in is needed, cause easyb is written in Groovy. For installation, just use the URL http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.5/ in Help >> Install new software. If you are already using Eclipse Helios, go here to download a version of the Groovy Plug-in. If you have any problem or want a tutorial for the plug-in,this page contains everything you need to know about it. This plug-in is only needed as a dependency for the easyb one.
Then, proceed to install easyb plug-in. It is installed the same way, just Help >> Install new software with the URL http://easyb.googlecode.com/svn/trunk/eclipse-plugins/org.easyb.eclipse.updatesite/ It works in both Eclipse 3.5 and 3.6.
Writing a spec
As an example, a little spec for GeoPoint. First, we need to initialize some points. For that, in first place, the test.geogebra.kernel package is created. Then, geogebra.kernel.Kernel and geogebra.kernel.GeoPoint are imported. Then, because we will need some points in each spec, we need a before like this one.
before "initialize some points for each spec", {
krnl = new Kernel(null)
point = krnl.Point("p", 0.5, 0.4, false)
orig = krnl.Point("orig", 0.0, 0.0, false)
mid = krnl.Midpoint(point, orig)
}
Then, we can test that point and orig should be independent. For testing it, we write a spec like the following example:
it "should be independent",{
point.independent.shouldBe true
orig.isIndependent().shouldBe true
}
it is a method that receives two parameters, a String and a closure. If you don't know what a closure is, read the chapter in the Groovy User Guide. In the closure, we say that point.independent.shouldBe true. Look at how readable it is (well, RSpec is even more readable, point.should be_independent). Both lines test the same but for different objects.
Running specs
For running the specs, just select the file and use the Run As >> Behaviour contextual menu.
