class SkeletonTest
Same name in other branches
- 3.x modules/testing_example/tests/src/Functional/SkeletonTest.php \Drupal\Tests\testing_example\Functional\SkeletonTest
- 4.0.x modules/testing_example/tests/src/Functional/SkeletonTest.php \Drupal\Tests\testing_example\Functional\SkeletonTest
Skeleton functional test.
This test shows you how you can add a failing test in order to make sure the test you've set up is discovered by the test runners. The test is not initially set up to fail. You have to modify the testFail() method to see the fail.
Each part of this test is required, and has comments explaining why it's there.
You can run this test using either phpunit or run-tests.sh. To use phpunit to make sure the test is discovered, you can call it like this:
cd drupal/root
SIMPLETEST_BASE_URL=http://example.com/ ./vendor/bin/phpunit -c core/ --testsuite functional --filter SkeletonTest
For run-tests.sh:
cd drupal/root
php ./core/scripts/run-tests.sh --browser --url http://example.com --types PHPUnit-Functional testing_example
All tests must have a least one group annotation. run-tests.sh uses the first one only.
@group testing_example @group examples
Hierarchy
- class \Drupal\Tests\testing_example\Functional\SkeletonTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of SkeletonTest
Related topics
File
-
testing_example/
tests/ src/ Functional/ SkeletonTest.php, line 55
Namespace
Drupal\Tests\testing_example\FunctionalView source
class SkeletonTest extends BrowserTestBase {
/**
* The theme to install as the default for testing.
*
* When using the default testing install profile we need to specify
* which theme to use when running functional tests.
*
* For tests that do not rely on any specific markup, or at least not Drupal
* core markup, use 'stark'. For tests that rely on core markup use 'stable'.
*
* @link https://www.drupal.org/node/3083055
*
* @var string
*/
protected $defaultTheme = 'stark';
/**
* Modules to install.
*
* This array of modules will be enabled when the fixture Drupal site is
* built. We leave it empty here because this is a skeleton test. A typical
* test will enable basic modules like node and user.
*
* @var string[]
*/
public static $modules = [];
/**
* This test method fails, so we can be sure our test is discovered.
*/
public function testFail() {
// We comment out the fail assertion so that normal automated tests for
// Examples don't fail. Uncomment the next line to see a fail.
// $this->fail('The test runner found our test and failed it. Yay!');
//
// PHPUnit will complain if there is no assertion in our test method, so we
// add this passing assertion. Comment or delete it if you'd like.
$this->assertTrue(TRUE);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
SkeletonTest::$defaultTheme | protected | property | The theme to install as the default for testing. |
SkeletonTest::$modules | public static | property | Modules to install. |
SkeletonTest::testFail | public | function | This test method fails, so we can be sure our test is discovered. |