Kasus pengujian untuk semua file

Artikel ini menjelaskan uji yang dijalankan menggunakan peralatan uji templat untuk file JavaScript Object Notation (JSON). Contohnya termasuk nama uji atau sampel kode yang berhasil atau gagal dalam pengujian. Selengkapnya tentang cara menjalankan pengujian atau cara menjalankan pengujian tertentu, lihat Parameter pengujian.

Menggunakan sintaks JSON yang valid

Nama uji: JSONFiles Harus Valid

Tes ini memeriksa bahwa semua file JSON mengandung sintaks yang valid. Misalnya, file azuredeploy.json, azuredeploy.parameters.json, atau createUiDefinition.json. Jika pengujian gagal, Anda akan melihat kegagalan atau peringatan untuk pengujian lain, atau penguraian JSON.

Contoh file templat

Contoh berikut gagal karena di azuredeploy.json kurung kurawal utama ({) hilang dari parameters, comboBox, dan location.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters":
    "comboBox":
      "type": "string"
    },
    "location":
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "comboBox": {
      "type": "string",
      "value": "[parameters('comboBox')]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

Contoh berikut berhasil.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "comboBox": {
      "type": "string"
    },
    "location": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "comboBox": {
      "type": "string",
      "value": "[parameters('comboBox')]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

Contoh berkas parameter

Contoh berikut gagal karena azuredeploy.parameters.json menggunakan parameter tanpa value.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value":
    }
  }
}

Contoh berikut berhasil.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "value": "westus"
    }
  }
}

Contoh CreateUiDefintion

Contoh berikut gagal karena di createUiDefinition.json tanda kurung kurawal ({) tidak ada di bagian outputs.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs":
      "comboBox": "[basics('comboBox')]",
      "location": "[location()]"
    }
  }
}

Contoh berikut berhasil.

{
  "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
  "handler": "Microsoft.Azure.CreateUIDef",
  "version": "0.1.2-preview",
  "parameters": {
    "basics": [
      {
        "name": "comboBox",
        "type": "Microsoft.Common.DropDown",
        "label": "Example drop down",
        "toolTip": "This is a tool tip"
      }
    ],
    "steps": [],
    "outputs": {
      "comboBox": "[basics('comboBox')]",
      "location": "[location()]"
    }
  }
}

Langkah berikutnya