mock

Python之mock接口开发

雨燕双飞 提交于 2019-12-04 01:59:42
import flask import json import pymysql import tools #mock接口开发 #1.模拟接口的意思 #2.给别人提供数据 #3.flask是一个web开发框架 server=flask.Flask(__name__) # @server.route('/api/login',methods=['post','get']) # def login(): # username=flask.request.values.get('username') # password = flask.request.values.get('password') # d={'error_code':1,'msg':'登陆成功','username':username,'password':password} # return json.dump(d,ensure_ascii=False) @server.route('api/get_bill') def get_bill(): table_list=['app_myuser','czm'] table_name=flask.request.values.get('table_name') limit=flask.request.values.get('limit',50) if table_name

Jest单元测试进阶

☆樱花仙子☆ 提交于 2019-12-04 01:41:40
   Jest 命令行窗口中的指令   在学习Jest单元测试入门的时候,我们给Jest命令提供了一个参数 --watchAll, 让它监听测试文件或测试文件引入的文件的变化,从而时时进行测试。但这样做也带来一个问题,只要改变一点内容,Jest就会把所有的测试都跑一遍,有点浪费资源。有没有可能对--watchAll模式进行进一步的优化,那是有的, 在什么地方呢?在命令窗口中。执行npm run test, 测试完成后,你会发现还有很多提示(Watch Usage),这些就是对--watchAll模式的优化   Press f to run only failed tests. 按f 键,进入一种模式,它只跑失败的测试用例。当我们执行npm run test 的时候,发现有一个测试失败了,这时我们只想跑失败的测试用例,那就按f吧。演示一下,随便把一个测试用例改为错误,比如 把request 的mock 改为name: 'jason' jest.mock('request', () => { return (url, callback) => { callback(null, 'ok', {name: 'jason'}) } });   这时测试重新跑了一遍了(watchAll 模式),命令窗口中显示了错误, 并且在最下面显示press w to show more, 同时光标在闪烁

mock挡板接口开发

怎甘沉沦 提交于 2019-12-04 00:05:06
import flaskimport json#mock接口开发 挡板#1、模拟第三方接口#2、 给别人提供数据#3、flask是一个web开发框架server = flask.Flask(__name__)@server.route('/api/login')#URL中的ip地址后面的内容/api/logindef login(): d = {'error_code':1,'msg':'登录成功'} return json.dumps(d,ensure_ascii=False)#ensure_ascii=false用来解决返回的消息中有中文的时候的乱码问题server.run(host='0.0.0.0',port=8000,debug=True)#debug=true,更新代码的时候,不需要重启 来源: https://www.cnblogs.com/lapt/p/11824599.html

C# Moq

流过昼夜 提交于 2019-12-03 21:41:45
Moq 1 My Cases 1.1 简单入门 2 Reference 2.1 Methods 2.2 Matching Arguments 2.3 Properties 2.4 Events 2.5 Callbacks 2.6 Verification 2.7 Customizing Mock Behavior 2.8 Miscellaneous 2.9 Advanced Features 2.10 LINQ to Mocks 3 FAQ 3.1 static class/method 1 My Cases 1.1 简单入门 // 假定我有一个 MyFactory 用来创建 MyInterface 实例 // 创建 MyFactory 的 Mock 对象 var mockFactory = new Mock<MyFactory>(); // 创建 MyInterface 的 Mock 实例 var mockInstance = new Mock<MyInterface>(); // 使用 Moq 实现如果调用 MyInstance.DoSomething(bool) 方法无论传入参数为何值一概抛出 MyException 异常 mockInstance.Setup(c => c.DoSomething(It.IsAny<bool>())) .Throws(new

在py文件中运行flask cli命令

主宰稳场 提交于 2019-12-03 15:01:47
主要是打包成exe之后,用于运行命令行。 命令行是 @app.cli.command() def mock(): ... 这样定义的 本来是用flask mock 这样方式运行的 打包后,希望用 app.exe mock的方式运行。 找了半天,也没找到,最后参考flask github里的 https://github.com/pallets/flask/blob/master/tests/test_cli.py , 搞定 app.py 上面的部分略过 ......if __name__ == '__main__': print(sn_harddisk) print(cpu_info) print(disk_info) app = create_app() if len(sys.argv) == 2: #命令行方式运行 if sys.argv[1] == 'mock': app.test_cli_runner().invoke(args=["mock"]) else: app.run() 用cx_Freeze 可以打包。 来源: https://www.cnblogs.com/xuanmanstein/p/11801351.html

Set a mock GPS location on an Android device

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am working on automating some device/server testing we do on various android devices. I need a way to set a specific GPS lat/long on an actual Android device that is usable within a NUnit testing framework. Any help on this will be appreciated. 回答1: You need to set Allow mock locations true under Developer settings . After that you can write some small utility app which will set mock location on receiving some custom event. You can then set location using adb shell command e.g $ adb shell am start -a android.intent.action.SET_CUSTOM_MOCK

org.mockito.exceptions.misusing.NotAMockException on InjectMocks object

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to mock the return value from a method but I'm getting NotAMockException . @InjectMocks private MyService myService; @Mock private OtherServiceUsedInMyServiceAsAutowired otherServiceUsedInMyServiceAsAutowired; Inside MyService I have a method called myMethod() and I want to return dummy object when this method is called. doReturn(someDummyObject).when(myService).myMethod(any(), any(), any()); And at that point I'm getting the error. What am I doing wrong? Full error: org.mockito.exceptions.misusing.NotAMockException: Argument

Mock Entity Framework long LINQ query

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Have a LINQ query expression (below) that want to test mocking the Entity Framework. To mock I am using the code: Entity Framework Testing with a Mocking Framework This works for other queries but doesn't work for this var query = from vwPs in _reportingDbContext.VwAccountNumber join ps in _reportingDbContext.PaymentSummary on new { Key1 = vwPs.Id, Key2 = vwPs.AccountNumber, Key3 = true, Key4 = true } equals new { Key1 = ps.Id, Key2 = ps.AccountNumber, Key3 = ps.PaymentDate >= fromDateTime, Key4 = ps.PaymentDate < toDateTime } into

How do you Mock an class for a unit test that has a return type but no input parameters

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a method in code that returns an OrganisationModel. public virtual OrganisationModel GetCurrentUserOrganisation() { var user = DBEntities.AspNetUsers.Find(_userId); if (user.ActiveOrganisation != null) { var org = user.OrganisationUsers.Where(p => p.organisationId == user.ActiveOrganisation).Where(p => p.userId == _userId).FirstOrDefault(); if(org != null) { if (org.Organisation != null) { return org.Organisation.ToModel(); } return null; } else { return null; } } return null; } I want to write a unit test on a class that uses this

Cannot mock/spy final class using PowerMockito.spy()

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use PowerMockito to create a spy of a final class but I keep getting the following error, even though I am using PowerMockito's spy() method in place of Mockito's: java.lang.IllegalArgumentException: Cannot subclass final class class com.whoever.WidgetUploadClient My test case looks something like this: ... import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.spy; @RunWith(PowerMockRunner.class) @PowerMockRunnerDelegate(RobolectricTestRunner.class) @PowerMockIgnore({