In order to give at least the appearance of test-driven development, we should port the existing menu_example D7 SimpleTest tests to D8.

These tests should be ported as directly as possible, without changing them.

Note that these tests will fail. :-) The point of this exercise is to write tests that fail.

This issue will be marked fixed when they run without fatal code errors.

In order to build the tests, you will also need to generate the file structure of the module.

One thing to keep in mind is that SimpleTest shows you a stack trace for fails, as if they were errors. This is the most annoying part of porting tests; they look like they're broken when they're really not.

Steps to take:

  • Assign the issue to yourself.
  • Generate a module skeleton.
  • Convert tests.
  • Run tests.
  • More conversion if necessary.
  • Submit a patch.

Resources:

A tool to generate a module skeleton: https://drupal.org/sandbox/mile23/2230027

Test conversion notes: https://drupal.org/node/2166895

How to run tests:

Comments

mile23’s picture

StatusFileSize
new4.9 KB
mile23’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mimran’s picture

Assigned: Unassigned » mimran
Status: Closed (fixed) » Active
mimran’s picture

Assigned: mimran » Unassigned
Status: Active » Fixed
mimran’s picture

Assigned: Unassigned » mimran
Status: Fixed » Active
mimran’s picture

StatusFileSize
new5.42 KB
new376 bytes

Updated the patch with some changes and attached the test results as well for the review purpose.

mimran’s picture

Assigned: mimran » Unassigned
Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: examples-menu-example-test-2277667-7-8.x.patch, failed testing.

joshi.rohit100’s picture

+++ b/menu_example/menu_example.module
@@ -0,0 +1,16 @@
+ */
+function menu_example_help($path, $arg) {
+  switch ($path) {
+    case 'mymodule/path':
+      return '<p>' . t('Make this helpful.') . '</p>';
+  }
+}

wrong hook_help() implementation

+++ b/menu_example/src/Tests/MenuExampleTest.php
@@ -0,0 +1,127 @@
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Menu example functionality',
+      'description' => 'Checks behavior of Menu Example.',
+      'group' => 'Examples',
+    );
+  }
+

Now not required

joshi.rohit100’s picture

+++ b/menu_example/menu_example.module
@@ -0,0 +1,16 @@
+ */
+function menu_example_help($path, $arg) {
+  switch ($path) {
+    case 'mymodule/path':
+      return '<p>' . t('Make this helpful.') . '</p>';
+  }
+}

wrong hook_help() implementation

+++ b/menu_example/src/Tests/MenuExampleTest.php
@@ -0,0 +1,127 @@
+  /**
+   * {@inheritdoc}
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'Menu example functionality',
+      'description' => 'Checks behavior of Menu Example.',
+      'group' => 'Examples',
+    );
+  }
+

Now not required

mimran’s picture

StatusFileSize
new5.37 KB

Hi @joshi,
Thanks for your reply and i have updated the patch as per your comment

mimran’s picture

StatusFileSize
new5 KB

Only intention of this was to create test cases for the menu_example module so i'm gonna work on other parts of the code in a separate issue

chx’s picture

Thanks for working on this! As far as I can see this looks good.

mimran’s picture

@chx thanks for the review

mimran’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: examples-menu-example-test-2277667-13-8.x.patch, failed testing.

mile23’s picture

+++ b/menu_example/src/Tests/MenuExampleTest.php
@@ -0,0 +1,116 @@
+/**
+ * Minimal test case for this module.
+ */
+class MenuExampleTest extends WebTestBase {

This needs @group annotation, or else it causes an exception:

Uncaught PHP Exception Drupal\simpletest\Exception\MissingGroupException: "Missing @group annotation in Drupal\menu_example\Tests\MenuExampleTest" at /Users/paul/pj2/drupal/core/modules/simpletest/src/TestDiscovery.php line 329

So add @group menu_example and we're good.

mimran’s picture

Assigned: Unassigned » mimran
mimran’s picture

StatusFileSize
new5.02 KB
new341 bytes

Updated the patch with@group annotation

mimran’s picture

Assigned: mimran » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 20: examples-menu-example-test-2277667-20-8.x.patch, failed testing.

snehi’s picture

Status: Needs work » Needs review
StatusFileSize
new5.02 KB

Upload without space.

Status: Needs review » Needs work

The last submitted patch, 23: examples-menu-example-test-2277667-20-8.x.patch, failed testing.

mimran’s picture

StatusFileSize
new343 bytes

@snehi i don't see any code changes on your commit over my previous one, attached the interdiff for the reviewers

snehi’s picture

+++ b/menu_example/src/Tests/MenuExampleTest.php
@@ -0,0 +1,118 @@
+ * ¶

Here was the extra space. Please check. I corrected it.
let me know if it is ok.

mimran’s picture

@snehi still i dont see your change please refer the interdiff of your patch and my previous patch

diff -u b/menu_example/src/Tests/MenuExampleTest.php b/menu_example/src/Tests/MenuExampleTest.php
--- b/menu_example/src/Tests/MenuExampleTest.php
+++ b/menu_example/src/Tests/MenuExampleTest.php
@@ -11,7 +11,7 @@
 
 /**
  * Minimal test case for this module.
- * 
+ *
  * @group menu_example
  */
 class MenuExampleTest extends WebTestBase {
mimran’s picture

StatusFileSize
new5.05 KB

Updated the patch by removing the space in EOF

mimran’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 28: examples-menu-example-test-2277667-28-8.x.patch, failed testing.

mile23’s picture

Status: Needs work » Fixed
Issue tags: -Novice

I think we're good here. :-)

I'm moving the patch to #1883724: Port menu_example to D8 where we can continue filling in the blanks and make the tests pass.

Also I'm making a note over there of proper git attribution for all the work here.

Thanks. :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.