mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-06 16:07:45 +08:00
feat: assert with openai model
This commit is contained in:
+10
-11
@@ -1,6 +1,7 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/uixt/types"
|
||||
@@ -8,16 +9,15 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func createAIService(t *testing.T) *AIServices {
|
||||
aiService := NewAIService(WithLLMService(LLMServiceTypeUITARS))
|
||||
require.NotNil(t, aiService)
|
||||
require.NotNil(t, aiService.ILLMService)
|
||||
return aiService
|
||||
func createAsserter(t *testing.T) *Asserter {
|
||||
asserter, err := NewAsserter(context.Background(), LLMServiceTypeUITARS)
|
||||
require.NoError(t, err)
|
||||
return asserter
|
||||
}
|
||||
|
||||
// 测试有效断言
|
||||
func TestValidAssertions(t *testing.T) {
|
||||
aiService := createAIService(t)
|
||||
asserter := createAsserter(t)
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
@@ -33,7 +33,7 @@ func TestValidAssertions(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "深度思考功能未开启",
|
||||
assertion: "输入框下方的「深度思考」文字是灰色的",
|
||||
assertion: "输入框下方的「深度思考」文字不是蓝色的",
|
||||
imagePath: "testdata/deepseek_think_off.png",
|
||||
expectPass: true,
|
||||
},
|
||||
@@ -50,7 +50,7 @@ func TestValidAssertions(t *testing.T) {
|
||||
imageBase64, size, err := loadImage(tc.imagePath)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := aiService.ILLMService.Assert(&AssertOptions{
|
||||
result, err := asserter.Assert(&AssertOptions{
|
||||
Assertion: tc.assertion,
|
||||
Screenshot: imageBase64,
|
||||
Size: size,
|
||||
@@ -58,14 +58,13 @@ func TestValidAssertions(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.NotNil(t, result)
|
||||
assert.Equal(t, tc.expectPass, result.Pass)
|
||||
assert.NotEmpty(t, result.Thought)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 测试无效参数
|
||||
func TestInvalidParameters(t *testing.T) {
|
||||
aiService := createAIService(t)
|
||||
asserter := createAsserter(t)
|
||||
testCases := []struct {
|
||||
name string
|
||||
assertion string
|
||||
@@ -91,7 +90,7 @@ func TestInvalidParameters(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
_, err := aiService.ILLMService.Assert(&AssertOptions{
|
||||
_, err := asserter.Assert(&AssertOptions{
|
||||
Assertion: tc.assertion,
|
||||
Screenshot: tc.screenshot,
|
||||
Size: tc.size,
|
||||
|
||||
Reference in New Issue
Block a user