0

Simply trying to get a node.

$this->drupalGet('node/25250');
$this->assertSession()->statusCodeEquals(200);

But this returns 404. I can browse to that node anonymously. Why is it returning 404?

1
  • Berdir is correct. All tests begin a new instance of Drupal (you can see the db tables created in your db if you watch). Using Behat/BDD, you can test against the same instance, but the process is a little different. – Kevin Jul 29 '17 at 19:31
3

BrowserTestBase do not run against your installation, they do a new installation and then run against that.

There is no content, no modules, pretty much nothing there by default, everything you need to need to create and install.

If you're looking for a way to run tests against your installation, you might be able to override the set up and tear down process. Or look at using behat: http://behat-drupal-extension.readthedocs.io/en/latest/intro.html

3
  • Behat would be good for tests that are not too involved. The Drupal Extension will take care of adding/removing supported entities for you, as well as being able to browse to existing pages with less setup than other methods of testing. – Kevin Jul 29 '17 at 19:35
  • That explains it. Now I guess I'm wondering why someone would use BrowserTestBase/phpunit over Behat? – cherner Jul 31 '17 at 15:32
  • 1
    behat is great for testing a specific site. BrowserTestBase is better for testing generic functionality in Drupal core contrib and custom modules. Core has thousands of test methods, testing many different setups and configurations, it is crucial that they do not interfere with each other. With behat, if you have a decent amount of tests, it is always a bit a struggle to making sure you clean up after your test, revert created content and changed configuration. – Berdir Jul 31 '17 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.