-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added README for test package. #414
Conversation
test/README.md
Outdated
exiting. To facilitate testing web applications, the ```webtest``` package provides utility methods such as ```webtest.NewRequest``` | ||
and ```webtest.Exec``` to allow the test writer to create request and test their execution against the web engine. | ||
|
||
Instead of registering the ```web``` module, use ```webtest.WithRealServer``` or ```webtest.WithMockServer``` to enable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you comment on the pros and cons of using WithRealServer
vs using WithMockServer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Their major difference is the test scenario and test target:
WithMockServer
:
- Does not start a real HTTP server, therefore does not requires network resources such as available port, firewall settings, etc.
- Mostly used for testing HTTP server-side implementation. (e.g. Controller, Middleware, etc.).
- Usually works together with
webtest.NewRequest()
andwebtest.MustExec()
for request mocking.
WithRealServer
:
- Create real HTTP server, therefore requires network resources.
- Suitable for mocking server-side implementation.
- Mostly used for testing client-side code that requires real HTTP interactions with another server. (e.g. http client, websocket client, etc.)
- In most of scenario, depending on the test purpose,
ittest.WithHttpPlayback
should be used instead as long as the remote server is accessible at time of development. webtest.NewRequest()
andwebtest.MustExec()
is optional in this mode. What it really does is to extract the random port automatically, which is also available viawebtest.CurrentPort(ctx)
PR Verification Succeeded: Coverage >= |
test/README.md
Outdated
```go | ||
func TestWithSubTests(t *testing.T) { | ||
RunTest(context.Background(), t, | ||
GomegaSubTest(SubTestAlwaysSucceed(), "SuccessfulTest-1"), | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because test
package contains multiple sub packages, I recommend to add package names in examples.
e.g.
func TestWithSubTests(t *testing.T) {
test.RunTest(context.Background(), t,
test.GomegaSubTest(SubTestAlwaysSucceed(), "SuccessfulTest-1"),
)
}
## apptest | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In each sub-package, maybe includes a minimum example code snippet makes the learning more smooth.
The examples in the example
folder might be too complex for beginners
test/README.md
Outdated
|
||
See the [examples](/dbtest/examples) directory for examples of using the ```dbtest``` package. | ||
|
||
## Suitetest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ittest
and sectest
are worth document a bit. Especially ittest
, I found it very useful in many testing scenarios
…ce. Added comments in test package.
test/README.md
Outdated
1. Set the `-record` flag when running the test from command line using ```go test``` or ```make test``` similar to the | ||
```dbtest``` package. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be -record-http
test/README.md
Outdated
Some application needs to interact with other services via HTTP. The ```httpclient``` package provides a way to do this. | ||
In order to test the application code that uses this package, the ```ittest``` package provides a way to record and playback | ||
the HTTP requests and responses. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ittest
is designed for any scenario where *http.Client
is used, not limited to httpclient
package. *recorder.Recorder
is available via DI
Description
Added a README file for test package to document how to write integration tests for go-lanai applications.
Updated the README for data package to reflect the latest change in the data package.
Type of Change
Checklist