From 0fe5b87134f4f3b6bdc744ef302bc727e51227c5 Mon Sep 17 00:00:00 2001 From: letty Date: Wed, 10 Jan 2018 10:47:10 +0800 Subject: [PATCH] doc: add more info in test.md Signed-off-by: letty --- docs/test/test.md | 102 ++++++++++++++++++++++++++++++---------------- 1 file changed, 68 insertions(+), 34 deletions(-) diff --git a/docs/test/test.md b/docs/test/test.md index fb66eed25..664951267 100644 --- a/docs/test/test.md +++ b/docs/test/test.md @@ -10,28 +10,52 @@ This doc will give an introduction about the following three parts: # Organization of test -Test in pouch could be divided into two parts [unit testing](https://en.wikipedia.org/wiki/Unit_testing#Description) and [integration testing](https://en.wikipedia.org/wiki/Integration_testing). More info could be get from the wiki page. For pouch developer, if your code is only used in a single module, then the unit test is enough. While if your code is called by multiple modules, integration tests are required. In pouch, both of them are developed using go language. More details could be got in [Unit Testing](#unit-testing) and [Integration Testing](#integration-testing). +Test in pouch could be divided into following parts: + +* [unit testing](https://en.wikipedia.org/wiki/Unit_testing#Description) +* [integration testing](https://en.wikipedia.org/wiki/Integration_testing) + +More info could be gotten from the wiki page. + +For pouch developer, if your code is only used in a single module, then the unit test is enough. While if your code is called by multiple modules, integration tests are required. In pouch, both of them are developed using go language. More details could be gotten in [Unit Testing](#unit-testing) and [Integration Testing](#integration-testing). # Usage of Test +Tests could be run through the target provided by `Makefile` in the root directory of pouch code. Also could be run manually. +To run the whole test, you could just run: + +``` +# make test +``` +Please note that, in order to run test, the following prerequisites are needed: + + * golang is installed + * docker is installed + + ## Unit Testing Unit testing uses [go testing](https://golang.org/pkg/testing/) package, named with `_test.go` postfix and always locates in the same directory with the code tested. [client/client_test.go](https://github.com/alibaba/pouch/blob/master/client/client_test.go) is a good example of unit test. -There are two ways to trigger unit test. First, use [Makefile](https://github.com/alibaba/pouch/blob/master/Makefile) target unit-test to run entire unit test, and the command is make unit-test in the root path of pouch. Second, use go test $testdir to run unit test in a specified directory. Here is an example: +There are two ways to trigger unit test. -``` -#go test ./client -ok github.com/alibaba/pouch/client 0.094s +* Using [Makefile](https://github.com/alibaba/pouch/blob/master/Makefile) target unit-test to run entire unit test. -# make unit-test - -# -``` + ``` + # make unit-test + ``` + +* Using go test $testdir to run unit test in a specified directory. + + ``` + #go test ./client + ok github.com/alibaba/pouch/client 0.094s + + ``` ## Integration Testing -Integration test is in `pouch/test`, programmed with `go language`. There are two kinds of integration test, API test named as `pouch_api_xxx_test.go` and command line test named as `pouch_cli_xxx_test.go` ("xxx" represents the test point). +Integration test is in `pouch/test`, programmed with `go language`. There are two kinds of integration test, API test named as `api_xxx_test.go` and command line test named as `cli_xxx_test.go` ("xxx" represents the test point). It uses [go-check](https://labix.org/gocheck) package, a rich testing framework for go language. It provides many useful functions, such as: @@ -43,38 +67,48 @@ It uses [go-check](https://labix.org/gocheck) package, a rich testing framework For other files, they are: * `main_test.go` : the entrypoint of integration test. -* `lib_common.go`: common lib functions. -* `lib_env.go` : ENV related args and functions. +* `utils.go`: common lib functions. +* `environment directory`: directory environment is used to hold environment variables. +* `command package`: package command is used to encapsulate CLI lib functions. +* `request package`: package request is used to encapsulate http request lib functions. -Before running integration test, users need to [build pouch](https://github.com/alibaba/pouch/blob/master/INSTALLATION.md) binary and launch `pouchd` daemon. -Then integration test could be run as following: -* run entire test: +There are two ways to trigger integration test. - ``` - #go test ./test - ``` -* run a single test suite: +* Using [Makefile](https://github.com/alibaba/pouch/blob/master/Makefile) target integration-test to run entire integration test. ``` - #go test -check.f PouchCreateSuite - OK: 3 passed - PASS - ok github.com/alibaba/pouch/test 3.081s + # make integration-test ``` -* run a single test case: +* Using go test to run integration test. Before running integration test, users need to [build pouch](https://github.com/alibaba/pouch/blob/master/INSTALLATION.md) binary and launch `pouchd` daemon. +Then integration test could be run as following: - ``` - #go test -check.f PouchHelpSuite.TestHelpWorks - OK: 1 passed - PASS - ok github.com/alibaba/pouch/test 0.488s - ``` -* run with more information: + * run entire test: - ``` - #go test -check.vv - ``` + ``` + #go test ./test + ``` + * run a single test suite: + + ``` + #go test -check.f PouchCreateSuite + OK: 3 passed + PASS + ok github.com/alibaba/pouch/test 3.081s + ``` + * run a single test case: + + ``` + #go test -check.f PouchHelpSuite.TestHelpWorks + OK: 1 passed + PASS + ok github.com/alibaba/pouch/test 0.488s + ``` + * run with more information: + + ``` + #go test -check.vv + ``` # Development of Test // TODO