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 5944807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:35:31+00:00 2026-05-22T16:35:31+00:00

For my unit tests I want to setup a database, populate it with base

  • 0

For my unit tests I want to setup a database, populate it with base information and run each tests within a session that rollbacks all changes made to the DB in order to always have a pristine copy for each tests.

I’m looking for something like

db withSession {
   <create my objects under test>
   <run operations>
   <run asserts>

   this.rollback()
}

The rollback function was in early versions of Scala Query but it seems that it is missing now. How should I implement this functionality?

Best regards

  • 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-22T16:35:32+00:00Added an answer on May 22, 2026 at 4:35 pm

    Here is a unit test that illustrates this behaviour

    https://github.com/szeiger/scala-query/blob/master/src/test/scala/org/scalaquery/test/TransactionTest.scala

    GitHub currently 404s on the link, but I pulled the source code out of the google cache:

    package org.scalaquery.test
    
    import org.junit.Test
    import org.junit.Assert._
    import org.scalaquery.ql._
    import org.scalaquery.ql.extended.{ExtendedTable => Table}
    import org.scalaquery.session.Database.threadLocalSession
    import org.scalaquery.test.util._
    import org.scalaquery.test.util.TestDB._
    
    object TransactionTest extends DBTestObject(H2Disk, SQLiteDisk, Postgres, MySQL, DerbyDisk, HsqldbDisk, MSAccess, SQLServer)
    class TransactionTest(tdb: TestDB) extends DBTest(tdb) {
      import tdb.driver.Implicit._
    
      @Test def test() {
    
        val T = new Table[Int]("t") {
          def a = column[Int]("a")
          def * = a
        }
    
        db withSession {
          T.ddl.create
        }
    
        val q = Query(T)
    
        db withSession {
          threadLocalSession withTransaction {
            T.insert(42)
            assertEquals(Some(42), q.firstOption)
            threadLocalSession.rollback()
          }
          assertEquals(None, q.firstOption)
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write unit tests with NUnit that hit the database. I'd like
I have a collection of Boost unit tests I want to run as a
In my repo trunk I have a directory unit-tests that I want to keep
I want that my unit tests to cover my POCO's. How should I test
We want to run our unit tests on our TFS server. We are running
I want to write a few unit tests that do not make any changes
I'm writing some unit tests that rely on StructureMap so I want to completely
I have some Web API methods that I want to write unit tests for.
I have a component that uses log4net. I want to create unit tests, that
I want to create unit tests for one of my project's classes but I'm

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.