Kategorien
Allgemein Book Review Scala

Book Review|Scala for Java Developers

Thanks to Packt Publishing I have got a free ebook copy of „Scala for Java Developers„.

Preface

All Java code samples are covered by the features of the Java language specification whereas the upcoming functional extensions of Java 8 are not part of the discourse.

Review / Summary

The book “Scala for Java Developers” by Thomas Alexandre is an introduction to the Scala language from a Java Developers perspective. It does not explain basic programming paradigms like object orientation beside a very small wrap up of the functional paradigm as it might not be well known to every Java coder. The book is organized into 10 sections which should be read in order and mostly build upon each other.

Kategorien
Gradle Quick Tip Scala

Deliver code coverage indices for Scala using Gradle and SCCT

This post is a kind of follow up post to Gradle rocking Scala Specs2 tests. After setting up the build supporting Specs2 tests we could take it a step further to provide information about the code coverage of the tests.

SCCT is a code coverage tool for Scala. One benefit of SCCT is that the output format is compliant, to the widely known Cobertura so it could easily integrated into Jenkins for example.

Kategorien
Gradle Programming Languages Quick Tip Scala

Gradle rocking scala specs2 tests

In preparation of the upcoming Coursera course „Reactive Programming“ I just want to refresh my Scala skills by porting the Coursera Downloader from Python to Scala.

Setting up the initial build with Gradle is quite easy using the Scala Plugin. Looking around for some testing framework I have chosen Specs2 . Running Gradle after building some simple unit tests shows up that the tests are not executed at all. The build passes without running one single tests. Even declaring the tests to be processed by a JUnit4 runner did not want show up a single tests result. So I came up with the following simple solution. I add a new specs2 task to my Gradle build using the specs2 file runner:

/**
 * Run Spec2 tests
 */
task specs(type: JavaExec, dependsOn: testClasses) {
    main = 'org.specs2.files'
    args = ['console']
    classpath sourceSets.main.runtimeClasspath
    classpath sourceSets.test.runtimeClasspath
    classpath configurations.testRuntime
    classpath configurations.runtime
}

The file runner will select all files matching .*Spec in the test source directory which default (src/test/scala) nicely conforms the default project setup. If necessary it could be adjusted by setting the specs2.srcTestDir system property. For more information on the Specs2 Runners refer to the Specs2 documentation.

Now you have only to hook in the test step execution which could be easily achieved by extending the test task to depend on the specs2 tasks as well:

/*
 * and  add them to the default test set
 */
test.dependsOn specs

Running the test target of the Gradle build once again shows up the execution of the specs2 target and all tests and specifications.

Update(09/04/2014)

Marino Borra points out that he could run the specs tests successfully with the default gradle test task by simply adding the @RunWith(classOf[JUnitRunner]) annotation.