Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running tests which match multiple groups

Tags:

phpunit

I have tests of various types (unit, acceptance, etc) which I have assigned multiple labels for granularity

/**
 * @test
 * @group unit
 * @group controllers
 */


/**
 * @test
 * @group unit
 */


/**
 * @test
 * @group controllers
 */

Is it possible to run phpunit tests that only match two or more groups? Something like

--group unit|controllers

In this case the only test that should run would be the first test as it has both the unit and controllers group while the other tests would not run.

Using the notation

--group unit,controllers

Runs all tests from unit and then all (or remaining - I can't quite remember) tests from controllers - In large projects this can cause long run times.

like image 739
myol Avatar asked Apr 20 '16 08:04

myol


People also ask

How to run tests included under groups in TestNG?

As seen in testng.xml, the groups are included under the <group> tag. As we want to run the tests included under both the groups (group1 and group2), we include the required group names under the <run> tag.

What is the matching method in the class TestNG_todogroup class?

The matching method in the class is test_BingSearch (). TestNG_ToDoGroup class: To run test methods whose name includes “.*ToDoApp.*” and exclude test method (s) whose name contains “.*Test1.*”, we use method groups in the following manner: The matching method in the class is test_Selenium4_ToDoApp_Test2 ().

How do I run tests that match a tag or expression?

To run tests that match a tag or several tags, you can do one of the following: In the Execution Plan editor of your project, create a test item and assign a tag or a tag expression to it. In a keyword test, use the Run Test operation to run tests that match a tag or a tag expression.

What is the best way to compare two groups of participants?

Therefore, methods typically used for within-participant comparisons (e.g. paired/dependent samples t-tests, repeated measures ANOVA, etc.) would normally be appropriate.


2 Answers

  • --group unit,controllers should work
  • --exclude also exists to run all tests except those in the group(s) specified
  • @group unit|controllers is not an allowed syntax
like image 92
Sebastian Bergmann Avatar answered Oct 16 '22 05:10

Sebastian Bergmann


You need to rethink usage of @group annotations, start with splitting to test suites. You can try to follow phpunit rules about files structure or define test suites using xml. For ex:

<phpunit bootstrap="src/autoload.php">
  <testsuites>
    <testsuite name="unit">
      <directory>webroot/*/Tests/Unit</directory>
    </testsuite>
    <testsuite name="integration">
      <directory>webroot/*/Tests/Integration</directory>
    </testsuite>

    <testsuite name="controllers">
      <directory>webroot/*/Tests/Integration/Controller</directory>
    </testsuite>

  </testsuites>
</phpunit>

@groups usually used to combine by business entity, for ex. to run all tests related to search functionality of your application.

more information here https://phpunit.de/manual/current/en/organizing-tests.html

like image 26
Ivan Avatar answered Oct 16 '22 07:10

Ivan