W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
如果要針對(duì)Java以外的語(yǔ)言生成測(cè)試,或者對(duì)驗(yàn)證程序構(gòu)建Java測(cè)試的方式不滿意,則可以注冊(cè)自己的實(shí)現(xiàn)。
SingleTestGenerator
接口使您可以注冊(cè)自己的實(shí)現(xiàn)。以下代碼清單顯示了SingleTestGenerator
界面:
package org.springframework.cloud.contract.verifier.builder import org.springframework.cloud.contract.verifier.config.ContractVerifierConfigProperties import org.springframework.cloud.contract.verifier.file.ContractMetadata /** * Builds a single test. * * @since 1.1.0 */ trait SingleTestGenerator { /** * Creates contents of a single test class in which all test scenarios from * the contract metadata should be placed. * * @param properties - properties passed to the plugin * @param listOfFiles - list of parsed contracts with additional metadata * @param className - the name of the generated test class * @param classPackage - the name of the package in which the test class should be stored * @param includedDirectoryRelativePath - relative path to the included directory * @return contents of a single test class * @deprecated use{@link SingleTestGenerator#buildClass(ContractVerifierConfigProperties, Collection, String, GeneratedClassData)} */ @Deprecated abstract String buildClass(ContractVerifierConfigProperties properties, Collection<ContractMetadata> listOfFiles, String className, String classPackage, String includedDirectoryRelativePath) /** * Creates contents of a single test class in which all test scenarios from * the contract metadata should be placed. * * @param properties - properties passed to the plugin * @param listOfFiles - list of parsed contracts with additional metadata * @param generatedClassData - information about the generated class * @param includedDirectoryRelativePath - relative path to the included directory * @return contents of a single test class */ String buildClass(ContractVerifierConfigProperties properties, Collection<ContractMetadata> listOfFiles, String includedDirectoryRelativePath, GeneratedClassData generatedClassData) { String className = generatedClassData.className String classPackage = generatedClassData.classPackage String path = includedDirectoryRelativePath return buildClass(properties, listOfFiles, className, classPackage, path) } /** * Extension that should be appended to the generated test class. E.g. {@code .java} or {@code .php} * * @param properties - properties passed to the plugin */ abstract String fileExtension(ContractVerifierConfigProperties properties) static class GeneratedClassData { public final String className public final String classPackage public final java.nio.file.Path testClassPath GeneratedClassData(String className, String classPackage, java.nio.file.Path testClassPath) { this.className = className this.classPackage = classPackage this.testClassPath = testClassPath } } }
同樣,您必須提供一個(gè)spring.factories
文件,例如以下示例中所示的文件:
org.springframework.cloud.contract.verifier.builder.SingleTestGenerator=/ com.example.MyGenerator
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: