快嘉sdkg使用手册(一)--小试牛刀

快嘉sdkg使用手册

快嘉sdkg是一个maven插件,工程师可以用来生成接口sdk代码和基于testng框架的接口测试用例代码,该sdk代码可以直接用于实际项目中使用,接口测试用例代码可直接用于研发过程的联调、自动化测试和冒烟测试。
快嘉sdkg项目地址:https://github.com/fastjrun/sdkg

前提

os:win7 64bit
user:Adminstrator
jdk:1.8
maven:apache-maven-3.2.2
具体环境信息可参看下图


image

快嘉sdkg安装

下载源码并安装到本地maven仓库

git clone https://github.com/fastjrun/sdkg.git
cd sdkg
mvn clean install

安装成功后显示如下图,这个过程可能会比较慢也可能会中断,多执行几遍就好了。


image

至此,sdkg-helper代码生成Maven插件和single-sdk-archetype快嘉sdk脚手架就生成好了,且被安装到本地maven仓库(C:\Users\Administrator.m2\repository)如下图所示,红框圈起来的就是刚才安装的sdkg相关jar包和pom。


image

另外,打开本地maven仓库(C:\Users\Administrator.m2\repository)下的archetype-catalog.xml



  
    
      com.fastjrun.share
      single-sdk-archetype
      1.0-SNAPSHOT
      single-sdk-archetype
    
  

可以看到新增快嘉sdk脚手架。

小试牛刀

先用快嘉sdk脚手架新建一个test-sdk工程

mvn archetype:generate -B -DgroupId=com.alibaba.share -DartifactId=test-sdk -Dpackage="com.alibaba.testsdk" -Dapiworld="test-sdk" -Dversion=1.1-SNAPSHOT -DarchetypeGroupId=com.fastjrun.share -DarchetypeArtifactId=single-sdk-archetype -DarchetypeVersion=1.0-SNAPSHOT -DarchetypeCatalog=local
# 查看test-sdk下生成什么文件
tree /F
─test-sdk
 │  .gitignore
 │  pom.xml
 │  test-sdk-client.xml
 │
 └─src
     ├─main
     │  ├─otherjava
     │  └─resources
     │      │  log4j2.xml
     │      │  test-sdk-sdk.properties
     │      │
     │      └─testdata
     │              local.properties
     │
     └─test
         └─resources
                 testng.xml
# 以上是无任何java代码的

用sdkg-helper代码生成Maven插件生成接口sdk代码和接口单元测试代码

cd test-sdk
mvn clean package -Dsdkg.skip=false
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test-sdk 1.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test-sdk ---
[INFO]
[INFO] --- sdkg-helper:1.0-SNAPSHOT:sdkgc (initialize phase) @ test-sdk ---
[INFO] test-sdk-client.xml
[INFO] com.alibaba.testsdk.
[INFO] .
[INFO] test-sdk
[INFO]
[INFO] --- build-helper-maven-plugin:3.0.0:add-source (add-source) @ test-sdk --
-
[INFO] Source directory: C:\workshop\test\test-sdk\src\main\otherjava added.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test-sdk -
--
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 2 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.2:compile (default-compile) @ test-sdk ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 24 source files to C:\workshop\test\test-sdk\target\classes
[INFO]
[INFO] --- maven-source-plugin:2.4:jar-no-fork (attach-sources) @ test-sdk ---
[INFO] Building jar: C:\workshop\test\test-sdk\target\test-sdk-1.1-SNAPSHOT-sour
ces.jar
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ te
st-sdk ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.6.2:testCompile (default-testCompile) @ test-
sdk ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to C:\workshop\test\test-sdk\target\test-classes

[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test-sdk ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-sdk ---
[INFO] Building jar: C:\workshop\test\test-sdk\target\test-sdk-1.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.120 s
[INFO] Finished at: 2018-05-20T21:21:29+08:00

接下来用 maven-surefire-plugin插件跑接口测试代码

mvn clean package -DskipTests=false
# 此处省略很长的一段输出
......
......
......
Tests run: 19, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.103 sec

Results :

Tests run: 19, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ test-sdk ---
[INFO] Building jar: C:\workshop\test\test-sdk\target\test-sdk-1.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.301 s
[INFO] Finished at: 2018-05-20T21:32:20+08:00
[INFO] Final Memory: 20M/121M
[INFO] ------------------------------------------------------------------------

这样,我们实现了test-sdk工程从无到有,从无代码到有代码,且能正常执行自动化测试的完整过程。

你可能感兴趣的:(快嘉sdkg使用手册(一)--小试牛刀)