Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4083604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:20:01+00:00 2026-05-20T18:20:01+00:00

I am trying to get scala specs and unitils-dbunit to work. To use unitils

  • 0

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

To use unitils you have to annotate your
test class with @RunWith(classOf[UnitilsJUnit4TestClassRunner]) or
extend from a class and you can set DataSet’s to load with
@DataSet(Array(“DataSet.xml”)). All of this works with JUnit.

But I got 2 problems when using specs:

  • I am running my specs tests with gradle and the ScalaTestAntTask, so
    I guess the @RunWith annotation will be ignored.
  • I can not set the @DataSet annotation to my test method as
    seen 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 definition

“querying the database” should {

^

Does somebody know how I can use specs and unitils together?

UPDATE: This is the solution I came up with:

    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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:20:02+00:00Added an answer on May 20, 2026 at 6:20 pm

    The DataSet annotation can’t be applied directly to "xxx" should because this is not a test method, just a regular scala code call.

    I can’t give you a fully working solution but what you need to do is to dig out the unitils API and use the DataSetFactory directly to load your data. I think that you can more or less reuse the code found here.

    Then, if you need to load this dataset before each example, just use a doBefore call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use scala.reflect to get the class attributes and to write them
I get this error when trying to use the lift-json library with scala play:
I have been trying to get a grasp on how implicit parameters work in
In trying to use Scala with JPA, I have the following snippet as part
I'm trying to get started with Scala and cannot get out of the starting
I'm trying to get a real equivalent for Java's public static final in Scala
I have 2 equal-length lists and I am trying to get scalar product of
I am trying get Struts 2 and Tiles to work and I am using
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to get this to work, with no luck: [DataMember] public Type ParameterType {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.