10.1 单体和功能测试

Drupal 8 龪龧龥龢龞龛龙龖龕龑龎龊龇龆龃龥龢龁齿齼龥龢齹龥龢齸齵齲齱龑齯齫齪齦齥龥龢齡齞齚齞齗齕齒齏齍齪齉齇齞齚齅齄齁鼽鼺龛龧齿齼齹鼷鼵齥龥龢齉齇鼳鼱鼮鼫龥龢齹鼧鼣鼡龧鼞鼜鼙鼖龕龑龎龊龧龥龢齪鼒鼏鼍鼊鼇鼆齍鼖齥龥龢齹

龆龃龥龢龁齿齼龥龢龧龞龛鼂鼀鼞龥龢龧黽黺齪龆龃龥龢黷齡龥龢黳黲龧齿齼齹Drupal 8 龪齪黯黫黪黩黥黢黠點黛黙齵龆龃龥龢齪鼖鼞默龖黩黥齸黔黒龖黐黙齵鼖黏黩黥龧齿齼鼍黌齪鼖齥黩黥鼏黋黈齲黆齡黃鼱龧 Drupal 黀麼麹齅麶麳黃鼱龧麯麬龁麪麧齹

齿齼龥龢鼞龥龢麦黛麥麡齱麠麝龧齿齼齹麛麘齪麗麔麑齼麎麌齡麋麇龪麅鼱鼵黏麃鹿齪鹾鹼鹹鹸鼷鼵黏麋麇鹴鹲鼖龑麃鹰齹龛鹭鹪鼖黏鹦鼺龛鼵黏鹣鹢龧 Drupal 黀麼齹鹦麑鹟鹞鹿鹝黽黺龧齿齼龥龢齪鼒鹜麔鹙鹗黠鹖齹

本课内容

  • 齏齍龆龃龥龢
  • 麅鼱龆龃龥龢
  • 齏齍齿齼龥龢
  • 麅鼱齿齼龥龢

初期安装

麗麔鹔齁黏鹑鹎鹋 test_example齹

test_example.info.yml

name: Test Example
type: module
description: Example showing how to create tests
core: 8.x
package: Examples
dependencies:
  - user
  - options

创建一个简单服务

黩黥鸨Services鸡鼞齼鸞鼳鼱龥龢龧鸝麛鸙齹

test_example.services.yml

services:
  test_example.conversions:
    class: Drupal\pants\TestExampleConversions

src/TestExampleConversions.php 鸎麝龇

<?php
 
/**
 * @file
 * Contains \Drupal\test_example\TestExampleConversions.
 */
 
namespace Drupal\test_example;
 
/**
 * Provide functions for converting measurements.
 *
 * @package Drupal\test_example
 */
class TestExampleConversions {
 
  /**
   * Convert Celsius to Fahrenheit
   *
   * @param $temp
   *
   * @return int
   */
  public function celsiusToFahrenheit($temp) {
    return ($temp * (9/5)) + 32;
  }
 
  /**
   * Convert centimeter to inches.
   *
   * @param $length
   *
   * @return int
   */
  public function centimeterToInch($length) {
    return $length / 2.54;
  }
 
}

评论 (写第一个评论)