mock

Python: how to mock a kafka topic for unit tests?

匿名 (未验证) 提交于 2019-12-03 00:53:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: We have a message scheduler that generates a hash-key from the message attributes before placing it on a Kafka topic queue with the key. This is done for de-duplication purposes. However, I am not sure how I could possibly test this deduplication without actually setting up a local cluster and checking that it is performing as expected. Searching online for tools for mocking a Kafka topic queue has not helped, and I am concerned that I am perhaps thinking about this the wrong way. Ultimately, whatever is used to mock the Kafka queue, should

GPS Provider unknown error in Set Mock Location?

匿名 (未验证) 提交于 2019-12-03 00:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to set my mock location however, I am getting the following error(Provider 'gps' unknown) and not to sure what is wrong? I've got all the permission declared in my manifest.xml along with all the parameters. Mock Location Method //Initiates the method to set the phones location private void setMockLocation() { mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER); mLocationManager.addTestProvider ( LocationManager.GPS_PROVIDER, "requiresNetwork" == "", "requiresSatellite" == "", "requiresCell" == "", "hasMonetaryCost"

How to mock a Kotlin singleton object?

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Given a Kotlin singleton object and a fun that call it's method object SomeObject { fun someFun () {} } fun callerFun () { SomeObject . someFun () } Is there a way to mock call to SomeObject.someFun() ? 回答1: Just make you object implement an interface, than you can mock you object with any mocking library. Here example of Junit + Mockito + Mockito-Kotlin : import com . nhaarman . mockito_kotlin . mock import com . nhaarman . mockito_kotlin . whenever import org . junit . Assert . assertEquals import org . junit . Test object

Mocking HttpClient.execute issues: Mockito

匿名 (未验证) 提交于 2019-12-03 00:46:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to test this method. @Override public JSON connectResource() throws IOException { //get the location and credentials for the certificates System.setProperty("javax.net.ssl.trustStore", "C:/Program Files/Java/jdk1.7.0_40/jre/lib/security/cacerts"); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); HttpRequest httpRequest = new HttpGet(url); System.out.println("hello"); httpRequest.addHeader("Accept", "application/json"); HttpResponse response = httpClient.execute((HttpUriRequest) httpRequest); System.out.println(

mock基本使用

匿名 (未验证) 提交于 2019-12-03 00:41:02
什么是mock? mock在翻译过来有模拟的意思。这里要介绍的mock是辅助单元测试的一个模块。它允许您用模拟对象替换您的系统的部分,并对它们已使用的方式进行断言。 > pip install -U mock 在Python3.x中,mock已经被集成到了unittest单元测试框架中,所以,可以直接使用。   可能你和我初次接触这个概念的时候会有这样的疑问:把要测的东西都模拟掉了还测试什么呢?   但在,实际生产中的项目是非常复杂的,对其进行单元测试的时候,会遇到以下问题: 接口的依赖 外部接口调用 测试环境非常复杂 我们先从最简单例子开始。 modular.py #modular.py class Count(): def add(self): pass mock_demo01.py from unittest import mock import unittest from modular import Count # test Count class class TestCount(unittest.TestCase): def test_add(self): count = Count() count.add = mock.Mock(return_value=13) result = count.add(8,5) self.assertEqual(result,13)

VUE-本地mock数据的方法

匿名 (未验证) 提交于 2019-12-03 00:39:02
如果后端接口的实现尚未编码完成,前端开发一般使用mock数据,以进行前端数据填充。 mock方法挺多,这里给出两种: 1. 使用Express静态服务器 build/dev-server.js 中添加如下代码: 2. 使用mock.js配合axios-mock-adapter mock.js:可以用来造各种通用类型的随机数据,开发人员就不需要手动造数据了。 axios-mock-adapter:请求模拟调试器 Mock.js官方网址: 在使用之前要安装此模块:npm install mockjs 在自己搭建的vue项目的src下,创建mock目录: 目录下包含: user.js:(用来造数据,如:名字,地址等) mock.js:(用来模拟请求chuli) 具体用哪种方式,要依据实际的情况,如果数据量以及数据的属性很少,使用express方法最简单。如果模拟的数据属性很多,手动写入模拟数据很花时间,并且想要模拟一些简单的增,删,改的操作,mock.js的方式就更合适一点。 文章来源: VUE-本地mock数据的方法

vue-cli mock数据

匿名 (未验证) 提交于 2019-12-03 00:37:01
在根目录建mock文件夹 var express = require( 'express' ) var apiRoutes = express . Router () ; var home = require( './mockdata/home.json' ) ; var daily = require( './mockdata/daily.json' ) ; ; apiRoutes.get( '/home' , function (req , res) { res. json (home) ; }) ; apiRoutes.get( '/daily' , function (req , res) { res. json (daily) ; }) ; 编辑build文件夹中dev-server.js文件中,增加 var apiRoutes = require( '../mock/apiroutes.js' ) app. use ( '/api' , apiRoutes) ; 整体结构如下 var port = process. env .PORT || config . dev . port // automatically open browser, if not set will be false var autoOpenBrowser = !! config . dev .

Mockito调用静态方法和void方法

匿名 (未验证) 提交于 2019-12-03 00:36:02
1 mock 静态方法 mockito库并不能mock静态方法,需要依赖powermock 第一步:给类添加注解 // 静态类优先加载,所以需要提前告诉powermock哪些静态类需要mock public class SupplierServiceImplTest extends PowerMockTestCase {} 第二步:mock使用 @Test (expectedExceptions = BusinessException.class) public void testAddSupplierAccount_genIdentityNoError () { // 告诉powermock,需要mock该类的所有静态方法 PowerMockito.mockStatic(PasswordGenerator.class); final SupplierAccountDto supplierAccountDto = new SupplierAccountDto(); supplierAccountDto.setName( "小明" ); final String randomPWd = "666" ; PowerMockito.when(supplierDao.selectByEmail(anyString())) .thenReturn( new ArrayList

Mockito调用静态方法和void方法

匿名 (未验证) 提交于 2019-12-03 00:36:02
1 mock 静态方法 mockito库并不能mock静态方法,需要依赖powermock 第一步:给类添加注解 // 静态类优先加载,所以需要提前告诉powermock哪些静态类需要mock public class SupplierServiceImplTest extends PowerMockTestCase {} 第二步:mock使用 @Test ( expectedExceptions = BusinessException . class ) public void testAddSupplierAccount_genIdentityNoError () { // 告诉powermock,需要mock该类的所有静态方法 PowerMockito . mockStatic ( PasswordGenerator . class ); final SupplierAccountDto supplierAccountDto = new SupplierAccountDto (); supplierAccountDto . setName ( "小明" ); final String randomPWd = "666" ; PowerMockito . when ( supplierDao . selectByEmail ( anyString ())) .

【Vue】vuecli mock模拟数据+json-server

匿名 (未验证) 提交于 2019-12-03 00:34:01
如果我们的项目利用的是前后端分离的话,前端后台是同时开发的,但是后台接口往往是落后于页面开发的,所以我前端就需要用到模拟的数据来替代后台的接口。 现在有很多的 mock数据工具 ,这里我们讲的是 json-server ,相对于简单,容易上手。 前提你们肯定应该安装了 node 了,然后在全局安装 json-server npm install json -server -g linux/mac版 sudo npm install json -server -g 建立好之后,然后打开终端输入 json- server db.json --port 3000 //(端口) 这里可以简化执行,具体操作: 打开 package.json 文件 然后在 scripts 中配置一个mock: "mock" : "json-server db.json --port 3003" 直接执行 npm run mock 然后可以看到 这里也可以直接访问 http:/localhost:3000 到这里我们已经开启了 json-server 的mock服务,同时我们在启动一个终端来启动 npm run dev 服务,这里我们需要保持两个服务都是开启的状态,不然会报 error 错,应为没开 json-serer服务 的话,访问不到这个地址。 这里我两个服务都是开启状态,直接在 HelloWorld