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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:11:25+00:00 2026-06-18T16:11:25+00:00

Is it possible to access the name of the currently executing test, from within

  • 0

Is it possible to access the name of the currently executing test, from within a ScalaTest test? (And how would I do it?)

Background:

I’m testing that my Data Access Object eventually throws an OverQuotaException if a user e.g. creates too many pages. These tests take rather long to run. To feel happier, I’d like to print the progress to stdout — and since there are quite many tests, I’d like to include the test name in the output, so I know what test is currently being run.

(I didn’t find any seemingly relevant function here: http://www.artima.com/docs-scalatest-2.0.M5/#org.scalatest.FreeSpec )

Example:

  "QuotaCharger can" - {
    "charge and decline quota consumers" - {

      "charge a per site IP number (guest user)" in {
         // ... Here, a guest user post very many comments until it's over quota.
         // This takes a little while, and there are many similar tests.

         // ---> Here <--- I'd like to access the string:
         //   "charge a per site IP number (guest user)",
         //  is that possible somehow?
      }
  • 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-06-18T16:11:26+00:00Added an answer on June 18, 2026 at 4:11 pm

    The intended way to do that is to override withFixture and capture the test data. In this use case, it is better to override withFixture in fixture.FreeSpec so you can pass the test data into each test rather than using a var. Info on that is here:

    http://www.artima.com/docs-scalatest-2.0.M5/org/scalatest/FreeSpec.html#withFixtureNoArgTest

    When I saw your question this morning I realized ScalaTest should have a trait that does this, so I just added one. It will be in 2.0.M6, the next milestone release, but in the meantime you can use a local copy. Here it is:

    import org.scalatest._
    
    /**
     * Trait that when mixed into a <code>fixture.Suite</code> passes the
     * <code>TestData</code> passed to <code>withFixture</code> as a fixture into each test.
     *
     * @author Bill Venners
     */
    trait TestDataFixture { this: fixture.Suite =>
    
      /**
       * The type of the fixture, which is <code>TestData</code>.
       */
      type FixtureParam = TestData
    
      /**
       * Invoke the test function, passing to the the test function to itself, because
       * in addition to being the test function, it is the <code>TestData</code> for the test.
       *
       * <p>
       * To enable stacking of traits that define <code>withFixture(NoArgTest)</code>, this method does not
       * invoke the test function directly. Instead, it delegates responsibility for invoking the test function
       * to <code>withFixture(NoArgTest)</code>.
       * </p>
       *
       * @param test the <code>OneArgTest</code> to invoke, passing in the
       *   <code>TestData</code> fixture
       */
      def withFixture(test: OneArgTest) {
        withFixture(test.toNoArgTest(test))
      }
    }
    

    You would use it like this:

    import org.scalatest._
    
    class MySpec extends fixture.FreeSpec with TestDataFixture {
      "this technique" - {
        "should work" in { td =>
          assert(td.name == "this technique should work")
         }
        "should be easy" in { td =>
          assert(td.name == "this technique should be easy")
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: javascript object, access variable property name? I'm trying to call a method
Is it possible to access the Data Purge Tool from the Valence API?
Is it possible to access arguments name strings?! function myFunction (a, b, c, d,
Im currently researching how to port the Data Access Layer of an existing .NET
I currently have a legacy system that uses SPs exclusively for access to the
Depending on machine I have to access file with same name but from different
I have a data set (currently in Access 2007 format) which has 2 tables,
I am currently getting data from a users profile when they login through facebook,
in objective-c can I access the calling classname/methodname within a method? Background: I am
Is this possible to acces selector with a general tag name. Like in sql

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.