Using unit specifications

I am trying to get scala specifications and unitils-dbunit to work.

To use unitils, you must annotate your test class with @RunWith (classOf [UnitilsJUnit4TestClassRunner]) or extend from the class, and you can set the DataSet to load using @DataSet (Array ("DataSet.xml")). All this works with JUnit.

But when using the specifications, I had 2 problems:

  • I run tests of my specifications with gradle and ScalaTestAntTask, so I think the @RunWith annotation will be ignored.
  • I cannot set the @DataSet annotation for my testing method as here:

    [...]
    @RunWith(classOf[UnitilsJUnit4TestClassRunner])
    class DaoTest extends Specification with ScalaTest {
    
        @TestDataSource
        var dataSource: DataSource = null
    
        @DataSet(Array("DataSet.xml"))
        "querying the database" should {
            "return the right data" in {
                [assertSomething]
            }
        }
    }
    

This gives me the following compiler error:

error: expected start of determination

"database query" should {

^

- , ?

UPDATE: , :

    import org.specs.runner.ScalaTest
    import org.specs.Specification
    import org.unitils.dbunit.DbUnitModule
    import java.io.File
    import java.util.Properties
    import org.unitils.core.ConfigurationLoader

    class DaoTest extends Specification with ScalaTest {

        "querying the database" should {

            doBefore {
                UnitilsDatabaseUtils.setup("DataSet.xml", "DataSet2.xml")
            }

            "return the right data" in {
                [test something]
            }
        }
    }

    object UnitilsDatabaseUtils {

        def setup(dataSetFileNames: String*) = {
            val configuration: Properties = new ConfigurationLoader().loadConfiguration
            val dbunitModule = new DbUnitModule
            dbunitModule.init(configuration)

            for (dataSetFileName <- dataSetFileNames) {
                val dataSetURL = getClass.getClassLoader.getResource(dataSetFileName)
                dbunitModule.insertDataSet(new File(dataSetURL.toURI))
            }
        }
    }

-  Christian

+3
1

DataSet "xxx" should, , scala.

, , API- DataSetFactory . , .

, , doBefore.

+3
source

All Articles