mock

mock接口框架

╄→尐↘猪︶ㄣ 提交于 2019-12-03 01:27:25
mock测试 在接口测试过程中,对于某些不容易构造或者不容易获取的对象,我们常常会用一个虚拟的对象代替以便测试。 mock 使用 https://github.com/dreamhead/moco One is API, which you can use in your unit test. The other is that run Moco as standalone. Currently, you put all your configuration in JSON file. 原理 根据配置,启动真正的HTTP服务(监听本地某端口)。发起请求满足一条件时,就会收到应答。 基于Netty的的网络应用框架编写。 mock 对象 单测 moco 启动 java -jar ./moco-runner-0.12.0-standalone.jar http -p 8888 -c demo.json demo [ { "description": "My mock demo", "request": { "uri":"/" }, "response": { "text": "Moco demo is running" } } ] get 热部署:服务不用停止,就可以完成升级。 [ { "description":"模拟一个没有参数的get 请求", "request":{ "uri":

Difference between @Mock, @MockBean and Mockito.mock()

匿名 (未验证) 提交于 2019-12-03 01:27:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When creating tests and mocking dependencies, what is the difference between these three approaches? @MockBean: @MockBean MyService myservice; @Mock: @Mock MyService myservice; Mockito.mock() MyService myservice = Mockito.mock(MyService.class); 回答1: Plain Mockito library import org.mockito.Mock; ... @Mock MyService myservice; and import org.mockito.Mockito; ... MyService myservice = Mockito.mock(MyService.class); come from the Mockito library and are functionally equivalent. They allow to mock a class or an interface and to record and verify

How to mock an activatedRoute parent Route in angular2 for testing purposes?

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have this export class QuestionnaireQuestionsComponent { questions: Question[] = []; private loading:boolean = true; constructor( private route: ActivatedRoute, public questionnaireService:QuestionnaireService) {} ngOnInit(){ this.route.parent.params.subscribe((params:any)=>{ this.questionnaireService.getQuestionsForQuestionnaire(params.id).subscribe((questions)=>{ this.questions = questions; this.loading = false; }); }); } } My component is actually working pretty well. Problem is that I want to unit test it but I can't figure

How do you substitute HttpClient in Aurelia?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm brand new to Aurelia. How would you change the following code to provide a dummy HttpClient, e.g. a json reader instead that would provide just a static set of json data, negating the need for a server in development. import {inject} from 'aurelia-framework'; import {HttpClient} from 'aurelia-fetch-client'; @inject(HttpClient) export class Users { heading = 'Github Users'; users = []; constructor(http) { http.configure(config => { config .useStandardConfiguration() .withBaseUrl('https://api.github.com/'); }); this.http = http; } activate

Mockito AbstractMethodError on initMocks

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: So I've been struggling pretty much all day trying to get Mockito to work for my Android project. I added everything to my Gradle build file: androidTestCompile 'org.mockito:mockito-core:2.0.29-beta' androidTestCompile "junit:junit:4.12-beta-3" androidTestCompile 'com.google.dexmaker:dexmaker:1.2' androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2' and have tried running a test that doesn't really do anything: @RunWith ( MockitoJUnitRunner . class ) public class LoginActivityTest extends ActivityInstrumentationTestCase2 {

Can mock objects setup to return two desired results?

匿名 (未验证) 提交于 2019-12-03 01:23:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Can mock objects be used to return more than one desired result like below? mockObject . Setup ( o => o . foo ( It . IsAny < List <string> >())). Returns ( fooBall ); mockObject . Setup ( o => o . foo ( It . IsAny <int> ())). Returns ( fooSquare ); 回答1: Yes, you can use these setups. Thus arguments of foo method call are different (any integer and any list of strings), you have two different setups here, each with its own return value. If you would have same arguments, then last setup would replace previous setup(s). Remember -

How to mock class method in RSpec expect syntax?

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a confusion about how to mock a class method using new expect syntax. This works: Facebook .should_receive(:profile) .with("token") .and_return({"name" => "Hello", "id" => "14314141", "email" => "hello@me.com"}) and this doesn't: facebook = double("Facebook") allow(facebook).to receive(:profile).with("token").and_return({"name" => "Hello", "id" => "14314141", "email" => "hello@me.com"}) Can someone tell me what is wrong here? 回答1: Here's what you want to do (no need for double ): allow(Facebook) .to receive(:profile) .with("token")

Mockito:How to mock method called inside another method

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am new to mockito and I am using mockito to test method which is calling another method and called method returns string. I tried but I am unable write test. Please help public class MyClass { protected String processIncominData(String input) { String request = ...; ... String response = forwardRequest(request); ... return response; } public String forwardRequest(String requestToSocket) { String hostname = socketServerName; int port = socketServerPort; String responseLine=null; Socket clientSocket = null; PrintStream outs=null;

How to mock HttpClientCertificate?

匿名 (未验证) 提交于 2019-12-03 01:22:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to unit test an action filter I wrote. I want to mock the HttpClientCertificate but when I use MOQ I get exception. HttpClientCertificate doesnt have a public default constructor. code: //Stub HttpClientCertificate </br> var certMock = new Mock<HttpClientCertificate>(); HttpClientCertificate clientCertificate = certMock.Object; requestMock.Setup(b => b.ClientCertificate).Returns(clientCertificate); certMock.Setup(b => b.Certificate).Returns(new Byte[] { }); 回答1: This is the most awkward case of creating unit testable systems in

PowerMock java.lang.ClassCastException: sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to javax.net.ssl.HttpsURLConnection

匿名 (未验证) 提交于 2019-12-03 01:21:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I created a mock HttpsURLConnection based on an StackExchange answer : import java.net.URL; import javax.net.ssl.HttpsURLConnection; ... @RunWith(PowerMockRunner.class) public class DialogTest { public void mockHttpsUrlConnectionExample() throws Exception { URL mockUrl = PowerMockito.mock(URL.class); PowerMockito.whenNew(URL.class).withAnyArguments().thenReturn(mockUrl); HttpsURLConnection mockUrlConnection = PowerMockito.mock(HttpsURLConnection.class); PowerMockito.when(mockUrl.openConnection()).thenReturn(mockUrlConnection); PowerMockito