Sebastian Benz

On Programming, DSLs and Testing.

Jnario @ Java User Group Munich

| Comments

If you are curios to see Jnario in action here is your chance! I will give a hands-on introduction next Monday in the Java User Group Munich. I won’t be wasting much time with slides, but instead use the time to develop a little application using BDD and Jnario. So its not only going to be a introduction to Jnario, but also to behavior-driven-development (BDD)!

A New Jnario Release!

| Comments

I am happy to announce the new Jnario 0.0.4 release! With this release, Jnario is finally compatible to Xtend 2.4. But there is more to this release than just the updated Xtend compatibility.

A new Type System

The type system of Xtend has been rewritten from scratch for Xtend 2.4. In the previous Xtend and Jnario releases, some corner cases could result in compile errors in the generated Java code. These are all fixed now. At the same time, the new type system is a lot faster resulting in shorter build times.

Jnario 0.4.0 is now based on the new type system. It further benefits from the type systems increased flexibility. For example, it is now possible to access extension fields from within nested specs:

describe "Extension in nested example groups" {
  extension Shouter = new Shouter
  describe "nested example group"{
    fact "Hello".shout => "HELLO"
  }
}

The same is true for features, where you can use extension which are defined in Background scenarios:

Feature: Extension fields in Backgrounds

Background:
    extension Shouter = new Shouter
  Given a background with extension
    "Hello".shout => "HELLO"

Scenario: Using the background extension
  Then we can use the extension
    "Hello".shout => "HELLO"

Beautiful Test Reports

It has always been possible to generate HTML reports for your specifications written in Jnario. This release adds the possibility to include whether a spec is currently passing or failing. All passing specs will be marked green and all failing specs will be marked red with the failure cause. This makes Jnario reports a great way to communicate the progress of your project with your stakeholders. These reports are generated using Maven. For a full example have a look here. Example report

Define your own Matchers

One feature of Jnario is that you can write more readable assertions using should. It provides a common set of matchers such as be or contains:

"Hello" should not be "World"
#["red", "blue"] should contain "red"

But it is also possible to define your own should matchers. This feature has been available for a while, but was not yet featured in the documentation. You can define your own should matchers by defining a method with the prefix should_XXXX, which needs to return a boolean value. For example, when we define a method should_eat:

def should_eat(String animal, String food){
  animal == "Monkey" && food == "Banana"
}

…then we can use eat in our should expressions:

"Monkey" should eat "Banana"
"Monkey" should eat "Rocks" throws AssertionError

Better Maven Integration

This release greatly improves the maven support in Jnario. All you need to do to start a new Jnario project is run:

 mvn archetype:generate                                    \
   -DarchetypeGroupId=org.jnario                           \
   -DarchetypeArtifactId=jnario-archetype                  \
   -DarchetypeVersion=0.4.0                                \
   -DgroupId=org.example                                   \
   -DartifactId=myproject

If you run afterwards:

 mvn test
 mvn org.jnario:report:generate

You can check out the newly generated doc at “target/jnario-doc”.

More

  • Validation error for duplicate step definitions.
  • Define super classes in features and specs using the @Extends annotation:
@Extends(typeof(MySuperClass))
describe "defining super classes"{
     ...
}
  • New wait helper for automatically waiting until a condition turns true:
fact "Wait for something"{
  // define wait condition using lambdas 
  waitUntil[1 > 0]
  // configuration options
  waitUntil[
    message = "Custom error message"
    duration = 100
    pollingInterval = 10
    1 > 0
  ]
}

Jnario Release 0.3.0

| Comments

I am happy to announce a new Jnario release! Jnario is a test framework for Java focusing on the design and documentation aspects of testing. For a general introduction to Jnario have a look at our presentation from the last Eclipse Con:

You can find a list of all new features and bug fixes over here. Please note that this release requires Xtend 2.3 and is not compatible with the latest Xtend 2.4 milestones. You can install Jnario via update site or Maven.

Software Craftsmanship in Munich

| Comments

Before actually performing on stage, musicians usually spent countless hours practicing their skills. Of course, learning an instrument is hard and requires lots of time and focus. But is learning an instrument so much different than learning to program? How much time do we actually spend honing our development skills? On the contrary - how often do we, as developers, go “on stage” without having actually practiced our skills and tools?

Scientific research has shown that it takes about 10 years or 1000 hours of practice to become an expert. The key is deliberative practice: trying new things outside the personal comfort zone. Learning with and from others is arguably the most efficient way to do so. However, finding likeminded developers outside the workplace is often difficult. The Softwerkskammer tackles this problem by providing a platform for software craftsmen across Germany for sharing their knowledge and training their skills. Today, there exist local Softwerkskammer communities in most major German cities and since recently also here in Munich!

If you are living in Munich and keen to practice with other developers, why not come to our next meeting on Thursday, November 15th? We will perform (as always) a hands-on-session, which will be based on the “Taking Baby Steps” format. It is a great way to practice programming and refactoring in small incremental steps. I can promise you this: it will definitely move you out of your comfort zone!

Global Day of Coderetreat in Munich

| Comments

Last year, over 1800 passionate software developers in 94 cities around the world spent a full day practicing the craft of software development using the coderetreat format. We had a great day here in Munich as well. This year on December 8th it is time for another global day of coderetreat! I am really happy that I will again be able to facilitate a coderetreat here in Munich. This year’s event will be hosted by E.S.R. Labs. Feel free to participate, if you are a passionate about software development and keen to spend a fun day together with other programmers.

What is a Coderetreat?

A coderetreat is a daylong event, focused on practicing the basic principles of good design without the pressure of having to get things done. The day is split into six sessions, in which you work on the same problem over and over again. In each session you will pair with a different programmer to maximize the knowledge transfer. The important thing is that after each session all the code that has been written so far is deleted. This gives you the chance in the next session to all start over again without being constrained by any design decisions you made in the previous one. The combination of pair programming with the focus on writing perfect code instead of solving the problem gives you a unique opportunity to improve your skills.

When & where?

The coderetreat will take place at the E.S.R. Labs office here in Munich. The address is:

St.-Martin-Straße 53
81669 München‎

We will start the day at 8:15 AM with a small breakfast and we will have time for a beer after the event at 6:00 PM. E.S.R. Labs provides Breakfast, lunch and drinks. The only thing you need to bring is your computer.

Registration

The registration starts on Tuesday November 13th. For more information check out the official page.

Jnario @ EclipseCon Europe 2012

| Comments

Autumn has come and with it the next EclipseCon Europe. I am looking forward to lots of interesting talks and discussions. Over the years EclipseCon has definitely become one of my favorite conferences. Again, the program committee did a great job setting up a great setting up the presentation line-up and I am hoping to learn lots of new things.

5 Things That Make Xtend a Great Language for Java Developers

| Comments

Xtend is a new programming language for the JVM. In contrast to other new languages for the JVM, Xtend stays very close to Java and uses the exact same type system. This makes Xtend really easy to learn if you already know Java. At the same time Xtend enriches Java with functionality greatly increasing developer productivity and making code easier to read. Over the last year I have been using Xtend on a regular basis and I can say that I really like it. Here is my completely subjective list of reasons why I think Xtend is a great language for Java developers.

New Jnario Release 0.2.0

| Comments

I am happy to announce the new Jnario 0.2.0 release! Jnario is still being actively improved and I am really happy with our progress. I have to admit that I really enjoy using Jnario by myself and I can’t imagine going back to JUnit (here is an implementation for game of life, I implemented using Jnario at the last code retreat I attended).

This release improves the tooling support for Jnario and fixes some problems when compiling specs. One great new feature is that the Jnario editor provides now quickfixes for creating new Java and Xtend types.

There is also a new quickfix for creating new methods in existing Java and Xtend types. This helps the development flow a lot, easing need-driven development.

The code completion for feature definitions has also been improved. You now get proposals for steps that don’t have an implementation yet. The code completion will also automatically add import statements for steps defined in different packages.

Finally, there have been some important fixes making the compilation of specs and features a lot more robust. This makes it now possible to use extension fields in your feature files. You can find a list of all fixed issues here.

The latest release can be installed via the update site or Maven. If you want to learn more about Jnario visit the official homepage www.jnario.org. There is a new tab in the Jnario documentation showing the original Jnario spec from which it is generated. For questions or discussions join the Jnario mailing list.

Test Suites on Steroids - Introducing Jnario Suites

| Comments

One of the new features of the latest Jnario release are specification suites. They are a great way to structure and document your specifications (if you haven’t heard of Jnario yet, it is a new language for testing Java applications, read my my previous post for a general introduction). In this post I want to give you a quick overview about Jnario suites and show you how we use them for the development of Jnario.

We completely bootstrapped the implementation of Jnario. This means we write all tests for Jnario with Jnario. One feature of Jnario we are using heavily is the possibility to convert specs to html documents. The complete Jnario documentation is created that way. Each documentation page is generated from an executable spec. Generating the documentation from specs saves a lot of time as you can use the same examples for testing and documenting your application. Furthermore, it ensures that all code samples in the documentation are correct. For example, here is a specification:

and this is what the generated documentation looks like:

However, at one point during the development of Jnario I had the problem that I needed to create an overview page for the documentation. The overview page was supposed to describe the structure of the documentation with links to the different subtopics. Creating it manually felt wrong as it takes away the advantage of being able to just generate the documentation without having to touch it. Furthermore, whenever I change the name of a specification file I would need to manually update the links in the overview page. Considering my forgetfulness, this would mean broken links galore.

When I thought about it, I realized that the underlying use case is actually pretty common: being able to group tests based on certain criteria. In JUnit you would use test suites for this. To solve my problem, I just had to take this concept one step further and add the possibility to provide additional documentation. This is exactly what you can do now with Jnario Suites. A suite looks like a normal document written in markdown syntax, but you have the possibility to reference other specs or suites. These references are actual links to the existing spec files, which means the editor provides code completion for available specs and shows validation errors if specs are missing. Even better a Jnario suite compiles into a normal JUnit test suite. This means you can execute Jnario suites like any other test suite. Here is the suite file for the overview page of the Jnario documentation:

Having to explicitly reference all specs in a project can become quite tedious over time. This is why it also possible to reference multiple specs at once by matching the qualified name of a specs using a regular expressions. Here is another suite from the Jnario code base that we are using to execute all Jnario specs in our test project:

So far I am really happy with the result. Jnario suites fill the gap between being able to write executable specs and being able to generate usable documentation from them. They are also useful during development, for example, I started using suites as todo lists for features that I need to implement (pro tip: there is a quickfix in the suite editor to add missing specs).

If you want to learn more about Jnario visit the official homepage www.jnario.org. There is also a mailing list available for questions and discussions. Follow me on twitter if you want to stay up-to-date with Jnario.

Announcing Our First Jnario Release

| Comments

I have always envied Ruby developers for the great test frameworks they have at their disposal, such as RSpec or Cucumber. However, I am mostly working in pure Java projects, which means having to use JUnit for writing tests. Of course, I could have used RSpec with JRuby to test my applications, but that would mean giving up type-safety when writing tests. Reimplementing something like RSpec in Java doesn’t really make sense, as Java doesn’t provide the required syntactic flexibility. It seemed like I was stuck with JUnit.

This changed last year, when Xtext introduced the possibility to reuse and integrate all kinds of Java language constructs right into your own DSL. This makes it possible to create DSLs that seamlessly interact with Java objects while providing excellent tool support. A good demonstration of the potential Xtext is Xtend. Xtend is a language extending Java with additional constructs such as lambda expressions that compiles to idiomatic Java code.

Using Xtext, it has now become feasible to create a language specifically for testing Java programs that tightly integrates with Java and features a syntax specifically designed for writing concise and readable tests. This is exactly what I have been working on together with my colleague Birgit. We are now happy to announce the first official Jnario release. To get started head over to the Jnario website.