mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
fix: unittest
This commit is contained in:
@@ -1,5 +1,55 @@
|
|||||||
from plugin.python.plugin import serve
|
import logging
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import funppy
|
||||||
|
|
||||||
|
|
||||||
|
def sum(*args):
|
||||||
|
result = 0
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
def sum_ints(*args: List[int]) -> int:
|
||||||
|
result = 0
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
def sum_two_int(a: int, b: int) -> int:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
def sum_two_string(a: str, b: str) -> str:
|
||||||
|
return a + b
|
||||||
|
|
||||||
|
def sum_strings(*args: List[str]) -> str:
|
||||||
|
result = ""
|
||||||
|
for arg in args:
|
||||||
|
result += arg
|
||||||
|
return result
|
||||||
|
|
||||||
|
def concatenate(*args: List[str]) -> str:
|
||||||
|
result = ""
|
||||||
|
for arg in args:
|
||||||
|
result += str(arg)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def setup_hook_example(name):
|
||||||
|
logging.warning("setup_hook_example")
|
||||||
|
return f"setup_hook_example: {name}"
|
||||||
|
|
||||||
|
def teardown_hook_example(name):
|
||||||
|
logging.warning("teardown_hook_example")
|
||||||
|
return f"teardown_hook_example: {name}"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
serve()
|
funppy.register("sum", sum)
|
||||||
|
funppy.register("sum_ints", sum_ints)
|
||||||
|
funppy.register("concatenate", concatenate)
|
||||||
|
funppy.register("sum_two_int", sum_two_int)
|
||||||
|
funppy.register("sum_two_string", sum_two_string)
|
||||||
|
funppy.register("sum_strings", sum_strings)
|
||||||
|
funppy.register("setup_hook_example", setup_hook_example)
|
||||||
|
funppy.register("teardown_hook_example", teardown_hook_example)
|
||||||
|
funppy.serve()
|
||||||
|
|||||||
@@ -220,11 +220,11 @@ def concatenate(*args: List[str]) -> str:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def setup_hook_example(name):
|
def setup_hook_example(name):
|
||||||
logging.warn("setup_hook_example")
|
logging.warning("setup_hook_example")
|
||||||
return f"setup_hook_example: {name}"
|
return f"setup_hook_example: {name}"
|
||||||
|
|
||||||
def teardown_hook_example(name):
|
def teardown_hook_example(name):
|
||||||
logging.warn("teardown_hook_example")
|
logging.warning("teardown_hook_example")
|
||||||
return f"teardown_hook_example: {name}"
|
return f"teardown_hook_example: {name}"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,18 @@ func TestLocateFile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLocatePlugin(t *testing.T) {
|
func TestLocatePythonPlugin(t *testing.T) {
|
||||||
// specify target plugin path
|
_, err := locatePlugin("examples/debugtalk.py")
|
||||||
_, err := locatePlugin("examples/plugin/debugtalk.py")
|
if !assert.Nil(t, err) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestLocateGoPlugin(t *testing.T) {
|
||||||
|
buildHashicorpPlugin()
|
||||||
|
defer removeHashicorpPlugin()
|
||||||
|
|
||||||
|
_, err := locatePlugin("examples/debugtalk.bin")
|
||||||
if !assert.Nil(t, err) {
|
if !assert.Nil(t, err) {
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,18 @@ func removeHashicorpPlugin() {
|
|||||||
os.Remove("examples/debugtalk.bin")
|
os.Remove("examples/debugtalk.bin")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestHttpRunner(t *testing.T) {
|
func TestHttpRunnerWithGoPlugin(t *testing.T) {
|
||||||
buildHashicorpPlugin()
|
buildHashicorpPlugin()
|
||||||
defer removeHashicorpPlugin()
|
defer removeHashicorpPlugin()
|
||||||
|
|
||||||
|
assertRunTestCases(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHttpRunnerWithPythonPlugin(t *testing.T) {
|
||||||
|
assertRunTestCases(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func assertRunTestCases(t *testing.T) {
|
||||||
testcase1 := &TestCase{
|
testcase1 := &TestCase{
|
||||||
Config: NewConfig("TestCase1").
|
Config: NewConfig("TestCase1").
|
||||||
SetBaseURL("http://httpbin.org"),
|
SetBaseURL("http://httpbin.org"),
|
||||||
@@ -66,8 +74,6 @@ func TestHttpRunner(t *testing.T) {
|
|||||||
testcase4 := &demoRefTestCaseJSONPath
|
testcase4 := &demoRefTestCaseJSONPath
|
||||||
|
|
||||||
r := NewRunner(t)
|
r := NewRunner(t)
|
||||||
r.saveTests = true
|
|
||||||
r.genHTMLReport = true
|
|
||||||
err := r.Run(testcase1, testcase2, testcase3, testcase4)
|
err := r.Run(testcase1, testcase2, testcase3, testcase4)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("run testcase error: %v", err)
|
t.Fatalf("run testcase error: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user