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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:02:30+00:00 2026-06-12T08:02:30+00:00

PHPUnit runs the setUp() method of a test class prior to running a specific

  • 0

PHPUnit runs the setUp() method of a test class prior to running a specific test.

I load up test-specific fixtures for every test in a test class and would prefer not to have to explicitly do so. I would ideally like to handle this automagically in the setUp() method.

If the setUp() method makes available the test class name and test method name this can be done.

Is the name of the test class and method that is about to be run available to me in the setUp() method?

  • 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-12T08:02:31+00:00Added an answer on June 12, 2026 at 8:02 am

    The easiest way to achieve this should be calling $this->getName() in setUp().

    <?php
    
    class MyTest extends PHPUnit_Framework_TestCase
    {
        public function setUp() {
            var_dump($this->getName());
        }
    
    
        public function testMethod()
        {
            $this->assertEquals(4,2+2,'OK1');
        }
    }
    

    And running:

    phpunit MyTest.php 
    

    produces:

    PHPUnit 3.7.1 by Sebastian Bergmann.
    
    .string(10) "testMethod"
    
    
    Time: 0 seconds, Memory: 5.00Mb
    
    OK (1 test, 1 assertion)
    

    In general I’d advise against doing this but there sure are cases where it can be a nice way to do things.

    Other options would be to have more than one test class and having all the tests that use the same fixtures together in one class.

    Another would be to have private setUp helpers and calling the appropriate one from the test case.

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

Sidebar

Related Questions

With PHPUnit I can successfully test if a specific call to a class properly
I have a PHPUnit test case class (consisting of some test functions). I would
I have a jenkins setup that runs some unit tests with PHPUnit. I would
When running a PHPUnit test, I would like to be able to dump output
I have a PHPUnit test that's using a Doctrine2 custom repository and Doctrine Fixtures.
I am running PHP unit as follows: phpunit --debug --verbose --coverage-clover=/tmp/test.xml and get the
I've problem when I used PHPUnit test framework Yii in Netbeans. I've a class
I'm having a problem when running my PHPUnit test of creating a new profile,
I'm trying to setup a unit test but whenever I run phpunit -c app
I'm running phpunit tests with zendframework using netbeans but the reports are not being

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.