Skip to content
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

Merged
merged 6 commits into from
Jun 3, 2024
Merged

Added README for test package. #414

merged 6 commits into from
Jun 3, 2024

Conversation

TimShi
Copy link
Contributor

@TimShi TimShi commented May 27, 2024

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

  • Bug Fix
  • New Feature
  • Breaking Change
  • Refactor
  • Documentation
  • Other (please describe)

Checklist

  • I have read the contributing guidelines
  • Existing issues have been referenced (where applicable)
  • I have verified this change is not present in other open pull requests
  • Functionality is documented
  • All code style checks pass
  • New code contribution is covered by automated tests
  • All new and existing tests pass

@TimShi TimShi requested a review from stonedu1011 May 27, 2024 14:54
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
Copy link
Contributor Author

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?

Copy link
Contributor

@stonedu1011 stonedu1011 May 27, 2024

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() and webtest.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() and webtest.MustExec() is optional in this mode. What it really does is to extract the random port automatically, which is also available via webtest.CurrentPort(ctx)

Copy link

github-actions bot commented May 27, 2024

PR Coverage Summary
Changed Statements 4
Covered Statements 4
Test Coverage 100.0%

PR Verification Succeeded: Coverage >= 70%

test/README.md Outdated
Comment on lines 24 to 29
```go
func TestWithSubTests(t *testing.T) {
RunTest(context.Background(), t,
GomegaSubTest(SubTestAlwaysSucceed(), "SuccessfulTest-1"),
)
}
Copy link
Contributor

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"),
	)
}

Comment on lines +36 to +37
## apptest

Copy link
Contributor

@stonedu1011 stonedu1011 May 27, 2024

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
Copy link
Contributor

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

test/README.md Outdated
Comment on lines 217 to 218
1. Set the `-record` flag when running the test from command line using ```go test``` or ```make test``` similar to the
```dbtest``` package.
Copy link
Contributor

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
Comment on lines 207 to 209
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.
Copy link
Contributor

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

@TimShi TimShi merged commit d469496 into main Jun 3, 2024
1 check passed
@TimShi TimShi deleted the feature/doc branch June 3, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants