java - 我们如何在 Java 中的 BDD 功能文件中将 JSON 对象列表作为 JSON 字符串传递
问题描述
下面是我的功能文件。
场景1:获取所有AppsCount
当我们请求所有应用程序时,我们得到 4 个应用程序,应用程序列表以 json 形式发送:
"[
{ '_id' : 'app1', 'Name' : 'App 1', 'Type' : 1, 'Rules' : [ { '_id' : 'Rule1', 'FilterCriteria' : 8 }, { '_id' : 'Rule2', 'FilterCriteria' : 4 } ], 'Email' : 'test@dell.com', 'IsSlackEnabled' : false, 'IsEmailEnabled' : true, 'IsSMSEnabled' : false, 'IsPhoneEnabled' : false, 'IsNonProdEnabled' : false, 'CreatedBy' : 'test@dell.com' },
{ '_id' : 'app2', 'Name' : 'App 2', 'Type' : 2, 'Rules' : [ { '_id' : 'Rule3', 'FilterCriteria' : 8 } ], 'Email' : 'test1@dell.com', 'IsSlackEnabled' : true, 'SlackChannel' : 'testChannel', 'IsEmailEnabled' : false, 'IsSMSEnabled' : false, 'IsPhoneEnabled' : true, 'IsNonProdEnabled' : false, 'CreatedBy' : 'test1@dell.com' },
{ '_id' : 'app3', 'Name' : 'App 3', 'Type' : 3, 'Rules' : [ { '_id' : 'Rule4', 'FilterCriteria' : 7 } ], 'Email' : 'test3@dell.com', 'IsSlackEnabled' : true, 'IsEmailEnabled' : false, 'SlackChannel' : 'testChannel2', 'IsSMSEnabled' : true, 'IsPhoneEnabled' : false, 'IsNonProdEnabled' : false, 'CreatedBy' : 'test3@dell.com' },
{ '_id' : 'app4', 'Name' : 'App 4', 'Type' : 1, 'Rules' : [], 'Email' : 'test4@dell.com', 'IsSlackEnabled' : false, 'IsEmailEnabled' : false, 'IsSMSEnabled' : false, 'IsPhoneEnabled' : true, 'IsNonProdEnabled' : false, 'CreatedBy' : 'test4@dell.com' }
]"
但这是一个问题,因为我们在编写 json 字符串时需要双引号
所以我尝试了以下功能文件。
场景 2:获取所有AppsCount
当我们请求所有应用程序时,我们得到 4 个应用程序,应用程序列表以 json 形式发送:
"[
{ "_id" : "app1", "Name" : "App 1", "Type" : 1, "Rules" : [{ "_id" : "Rule1", "FilterCriteria" : 8 }, { "_id" : "Rule2", "FilterCriteria" : 4 } ], "Email" : "test@dell.com", "IsSlackEnabled" : false, "IsEmailEnabled" : true, "IsSMSEnabled" : false, "IsPhoneEnabled" : false, "IsNonProdEnabled" : false, "CreatedBy" : "test@dell.com" },
{ "_id" : "app2", "Name" : "App 2", "Type" : 2, "Rules" : [ { "_id" : "Rule3", "FilterCriteria" : 8 } ], "Email" : "test1@dell.com", "IsSlackEnabled" : true, "SlackChannel" : "testChannel", "IsEmailEnabled" : false, "IsSMSEnabled" : false, "IsPhoneEnabled" : true, "IsNonProdEnabled" : false, "CreatedBy" : "test1@dell.com" },
{ "_id" : "app3", "Name" : "App 3", "Type" : 3, "Rules" : [ { "_id" : "Rule4", "FilterCriteria" : 7 } ], "Email" : "test3@dell.com", "IsSlackEnabled" : true, "IsEmailEnabled" : false, "SlackChannel" : "testChannel2", "IsSMSEnabled" : true, "IsPhoneEnabled" : false, "IsNonProdEnabled" : false, "CreatedBy" : "test3@dell.com" },
{ "_id" : "app4", "Name" : "App 4", "Type" : 1, "Rules" : [], "Email" : "test4@dell.com", "IsSlackEnabled" : false, "IsEmailEnabled" : false, "IsSMSEnabled" : false, "IsPhoneEnabled" : true, "IsNonProdEnabled" : false, "CreatedBy" : "test4@dell.com" }
] "
但是在创建步骤定义时,每个字段的值都会作为它自己的参数出现。
我知道
| field1 | field2 |
| value1 | value2 |
解决方案,但我的数据太大了,我想知道是否有办法直接传递 JSON 字符串。
解决方案
创建一个文件 text.json ..并将 json 输入放在文件中.. 将此文件放在类路径中..
在功能文件中将文件名放在这种情况下-text.json..
在类文件 stepdef 中读取文件名.. 在类路径中查找此文件..
使用 clasloader 加载此文件并使用 objectmapper 映射此 json。
推荐阅读
- python - 静态方法作为没有实例化的属性
- eclipse - 同一{}部分的代码的背景颜色?[ECLPISE]
- visual-studio - Mathematica 安装:在 Visual Studio 2019 上找不到 Microsoft Visual Studio \VC\bin
- python - Django admin - 用户名字段显示我的电子邮件而不是用户名
- java - 我的对象数组只打印最后输入的值java
- javascript - 根据下拉选择显示内容
- azure - 如何检查我的某些工作项是否有测试用例失败
- python - Python argparse 为参数设置 1 个或多个参数
- swift5 - 如何通过拖动边缘来调整 NSView 的大小?
- javascript - setImmediate() 和 setTimeout() 回调与 I/O 回调的优先级