feat: add a command to generating test files

This commit is contained in:
2023-07-24 15:06:26 +08:00
committed by Bryant He
parent cb5762720f
commit dd23c91192
6 changed files with 73 additions and 28 deletions

View File

@@ -0,0 +1,20 @@
"""
Service unit testing best practice.
"""
from nameko.testing.services import worker_factory
def test_example_service():
"""
Test example service.
"""
# create worker with mock dependencies
service = worker_factory(ServiceName) # TODO replace ServiceName with the name of the service and import it
# add side effects to the mock rpc dependency on the "remote" service
service.remote.hello.side_effect = lambda name: "Hello, {}!".format(name)
# test remote_hello business logic
assert service.remote_hello("Bryant") == "Hello, Bryant!"
service.remote.hello.assert_called_once_with("Bryant")