-
Notifications
You must be signed in to change notification settings - Fork 11
Home
#Specs2 Spring
Specs2 Spring is an extension of the Specs2 framework. Specs2 Spring includes code that will help you set up the context for the entire integration test--and by context, we mean the appropriate entries in the JNDI environment as well as the beans under test, autowired in to the instance of the test under execution. Finally, Specs2 Spring can be easily configured to run every example in its own transaction that rolls back automatically when the example completes.
The extension is meant to help you write tests in Scala to test your Spring code (whether implemented in Java or Scala). You will be able to take advantage of all the features of the Specs2 framework and apply them to the Spring test code.
Why bother, you ask? Because Specs2 and Scala allow you to be much more expressive in your tests. Consequently, your tests can focus on the essence of what is being tested, reducing the noise that the traditional Java code requires. A motivational example shows how to prepare test data, insert them to the RDBMS and then verify that some service method works as expected.
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.orm.hibernate3.HibernateTemplate
import org.specs2.spring.{BeanTables, HibernateDataAccess, Specification}
@IntegrationTest
class SomeComponentSpec extends Specification
with HibernateDataAccess with BeanTables {
@Autowired var someComponent: SomeComponent = _
/**
* Shows the usage of BeanTables and HibernateDataAccess to
* set up and insert test objects using the convenient tabular notation.
*/
"getByUsername finds existing Rider" in {
"age" | "username" | "name" | "teamName" |
32 ! "janm" ! "Jan" ! "Wheelers" |
30 ! "anic" ! "Ani" ! "Team GB" |> insert[Rider]
this.someComponent.getByUsername("janm").getName must_== ("Jan")
}
}
#The documentation
Start by looking at the Introduction, which explains the motation behind Specs2 Spring and typical usage scenarios. Follow up by learning how to construct and test Large Systems, which is very closely tied to setting up Test Data.
Finally, I would be delighted to have your contributions; to find out how to build Specs2 Spring from sources and for guide to contributions, read Building Specs2 Spring.