1+1=?qaSwesdfhhjjjj...

1+1=? jjjjjjjjjjjjjjjj_百度知道
1+1=? jjjjjjjjjjjjjjjj
jjjjjjjjjjjjjjjj
提问者采纳
提问者评价
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁经历的事情犹如天上的繁星,有的让我感动不已,有的让我羞愧难当,有的让我愤怒无比,有的让我感到庄严神圣,有的让我感到妙趣横生,有的让我体验成功的喜悦。现在我就把我成功的一件事讲给你听。
在我五年级暑假时,在公路上看着别人骑着自行车在飙车,不知有多威风。我羡慕极了。心想:要是有一天,我也骑车在街上兜风,不知道有多酷啊!久而久之,这种想学骑车的心理慢慢地在我心里“开花、结果”。终于有一天,我耐不住心中的寂寞,请求表哥教我骑车,在我再三的请求下,表哥无奈,只好依着我,带我去公园学骑车。表哥先把车骑到一片草地上,然后对我说:“骑车其实很简单,只要你扶着车把,再蹬上去,还要克服恐惧的心理,这样就行了。你先自己骑骑看,我在后面扶着后座。”太好了,我终于可以学骑车了,我心里像吃了蜜一样甜。我扶着车把,跨上坐垫,我心里像揣了只兔子似的,直跳,车把时而向左,时而向右,好像一不小心就会摔倒下来似的。我尽力抑制住自己紧张的心情,让自己平静下来,一会儿功夫,我便掌握了平衡的技巧。我心想:骑车原来这么简单,表哥见我骑得这么好,把手放开了,我一不留神,摔了个四脚朝天,我一骨碌爬了起来,我感觉有一阵疼痛,提起裤
童年的生活就像一道闪电,在眼前划过。可是,我童年的趣事却好像刻在我的脑海里,抹也抹不去,时常想起就会忍不住哈哈大笑。
  有一次,妈妈买回了一大包菜,见我趴在沙发上看电视,就说:“小醇,你去帮妈妈洗一下菜吧?”“好!”我爽快的答应了。妈妈说完便去客厅里看电视,我走进厨房看见平台上放着一大包蔬菜,有白菜呀,一大把;有茄子,三大根;有西红柿,五六个……。我犯傻了,这么多菜,叫才读幼儿园大班的我洗,真是的。“啊,有了!”我大叫,妈妈平时不是把这么多的衣服,塞进洗衣机里一同洗吗?那我不会也这样做?等一下,或许妈妈还会夸我呢!想到这我便拎起那一大包菜来到了洗衣机前,踮起脚掀开洗衣机盖子,把菜小心翼翼地放进去,然后又盖上盖子,最后按下电源按钮。听着“轰轰……”的洗衣机启动的声音,我坐在一旁,津津有味地想着自己有多聪明。过了一会儿,我想,菜洗干净了吧?嘿!菜不需要涮干,想罢,我便从坐位上站起来,按一下洗衣机的按钮,使洗衣机停止,当我掀开洗衣机盖子一瞧,“呀!”真是令我万分惊讶,菜呢?看那白菜剩下了“光杆司令”,而茄子好像被老鼠啃过一样,遍体鳞伤;还有西红柿已经杳无踪影了……我吓得出了一身
经历的事情犹如天上的繁星,有的让我感动不已,有的让我羞愧难当,有的让我愤怒无比,有的让我感到庄严神圣,有的让我感到妙趣横生,有的让我体验成功的喜悦。现在我就把我成功的一件事讲给你听。
在我五年级暑假时,在公路上看着别人骑着自行车在飙车,不知有多威风。我羡慕极了。心想:要是有一天,我也骑车在街上兜风,不知道有多酷啊!久而久之,这种想学骑车的心理慢慢地在我心里“开花、结果”。终于有一天,我耐不住心中的寂寞,请求表哥教我骑车,在我再三的请求下,表哥无奈,只好依着我,带我去公园学骑车。表哥先把车骑到一片草地上,然后对我说:“骑车其实很简单,只要你扶着车把,再蹬上去,还要克服恐惧的心理,这样就行了。你先自己骑骑看,我在后面扶着后座。”太好了,我终于可以学骑车了,我心里像吃了蜜一样甜。我扶着车把,跨上坐垫,我心里像揣了只兔子似的,直跳,车把时而向左,时而向右,好像一不小心就会摔倒下来似的。我尽力抑制住自己紧张的心情,让自己平静下来,一会儿功夫,我便掌握了平衡的技巧。我心想:骑车原来这么简单,表哥见我骑得这么好,把手放开了,我一不留神,摔了个四脚朝天,我一骨碌爬了起来,我感觉有一阵疼痛,提起裤Mockito- a great mock framework for Java development. - CodeProject
Sign in using
75.6K views145 bookmarked
&4.94 (28 votes)
4.94/5 - 28 votesμ 4.94, σa 1.04 []
Rate this:
Introduction
This artical will show some basic concepts of mocking framework, why we should use it and walkthrough a simple that applied Mockito in Java.
The concept of mocking&&Outside of the world of software development, the term “mock” means to imitate or to mimic. A “mock” can therefore be thought of as a stand-in, an imposter or as most commonly referred to as it pertains to softwaredevelopment, a fake.Fakes are often used as stand-ins for dependencies of the class under test.&Terms & Definitions&&Dependency – A dependency is when one class in an application depends upon another in order to perform its intended function. Dependencies are often stored in instance variables inside of the dependent class.&Class Under Test – When writing unit tests, the term “unit” generally refers to a single class and specifically the class against which the tests are written. The class under test is therefore the application class that is being tested.&Why Mock?&&When we learn to program, our objects are usually self contained. Any hello world has no dependencies on outside classes (System.out aside) and neither do many of the other classes we write in the process of learning a language. However, in the real world, software has dependencies. We have action classes that depend on services and services that depend on data access objects (DAOs) and the list goes on.& & & & & & & & & & & & & & & & & & & & & & &&The idea of unit testing is that we want to test our code without testing the dependencies. This test allows you to verify that the code being tested works, regardless of it's dependencies. The theory is that if the code I write works as designed and my dependencies work as designed, then they should work together as designed. The code below would be an example of this:&&import java.util.ArrayL
public class Counter {
public Counter() {
public int count(ArrayList items) {
int results = 0;
for(Object curItem : items) {
results ++;
} I know the above example is about as simple as you get, but it illustrates the point. If you wanted to test the method count, you would write at test that addressed how the count method works. You aren't trying to test that ArrayList works because you assume that it has been tested and works as designed. Your only goal is to test your use of ArrayList.&&The concept behind mock objects is that we want to create an object that will take the place of the real object. This mock object will expect a certain method to be called with certain parameters and when that happens, it will return an expected result.&What are the key mocking concepts?When it comes to mocking, there are only 3 things you really stubbing, setting expectations and verifying.&Some unit test scenarios don’t involve any of these, others involve only stubbing and others involve setting expectations and verifying.Stubbing&Stubbing is the process of telling your fake how to behave when it is interacted with. You can generally stub public properties (those with getters and/or setters) and public functions.When it comes to stubbing functions, you have a lot of choices typically. You may wish to return a specific value, throw an error or dispatch an event. Further, you may wish to indicate that the function behave differently depending upon how it is invoked (i.e. by matching the types or values of the parameters passed to the function).If this sounds like a lot of work, it can be, but it generally isn’t. One great feature of many of the mocking frameworks is that you need not stub void functions. Nor do you have to stub any functions that are not invoked or properties that are not consulted during the execution of your tests.Setting expectations&One of the key features of a fake is the ability to tell the fake what you expect when your test runs. For example, you may expect that a specific function be invoked exactly 3 times. You may expect that it never be invoked. You may expect that it be invoked at least twice, but not more than 5 times. You may expect that it be invoked with specific types of arguments or specific values or any combination of the above. The possibilities are endless.&Setting expectations is the process of telling your fake what you expect to happen to it. Remember that since it’s a fake, nothing actually happens. But, your class under test is none the wiser. From its perspective, it invoked the function and expects that it did whatever it was supposed to do.&For what it’s worth, most mocking frameworks let you create mocks of interfaces or public classes. You are not limited to having to mock only interfaces.&Verifying&Setting expectations and verification go hand in hand. Setting expectations is done prior to invoking the function(s) on the class under test. Verification is done after. So, first you set expectations, then you verify that your expectations were met.From a unit testing perspective, if your expectations were not met, the unit test fails. For example, if you set the expectation that the ILoginService.login function should be invoked exactly once with a specific username and password, but it was never invoked during the execution of your test, then the fake would not verify and the test should fail.&What are the benefits of mocking?&&&&You can cre TDD&&& & & & This one is one of the stronger benefits. If you create a Mock you can write Service Tests before the service is created, giving you the ability to add the tests to your automation environment in the development process. In other words, Service Mocking gives you the ability to use Test Driven Development.&& &Teams can work in parallel&& & & & This is
create tests for code that does not exist. But the previous point was for the developer who writes tests, this one is for the Testing Team. How does the team start creating tests when you don’t have anything to test? Mock it and write tests against the Mock! This means it’s actually possible for the QA Team to have a full suite of tests ready when a service i we don’t have downtimes when one team waits for the other to finish. This makes the financial argument for mocking particularly strong.&& &You can create proof of concepts or demos.&& & & & Since Mocks can (done levelheadedly) be very cost efficient to make, Mocks can be used to create a proof of concept, as a wireframe, or as a demo for something you’re considering building. This is very powerful and gives a good ground for making decisions about both whether to go ahead with a development project or not, but most importantly for actual design decisions.&&&You can write test for resource not accessible&& & & This is one of those benefits that doesn’t fall into the actual benefits category, but rather works as a life saver. Ever wanted to test or use a service, only to get told that the service is behind a firewall and that that firewall can’t be opened for you or that you’re an authorized to use it? When you do, a MockService placed in an accessible place, including on your local computer, is a life saver.&&&Mock can be delivered to the customer&& & & There are cases where there are reasons why you can’t allow access to your test systems for external sources, like partners or customers. These reasons can be access security, sensitivity of information, or just the fact that the test environment might not be accessible 24/7. I how do you provide a test system for your partner or customer to start development or test against? An easy solution is to provide a mock, either from your network or from your customers own network. A soapUI mock is extremely easy to deploy, it can either run in soapUI or exported as a .WAR file and placed in your java server of choice.&&&You can isolate systems&& & & Sometimes you would like to test a part of your system without having other system parts affect it. This because the other systems will add noise to the test data and make it harder to make good conclusions from the data collected. Using mocks you can remove all dependencies mocking all systems except the one system you need to pinpoint in your tests. When doing mocks for isolation these mocks can be made extremely simple but reliable, fast, and predictable. This gives you a test environment where you have removed all stochastic behavior, have repeatable patterns and can monitor specific systems well.&Mockito frameworkMockito is an open source testing framework for Java released under the MIT License.&Mockito distinguishes itself from other mocking frameworks by allowing developers to verify the behavior of the system under test (SUT) without establishing expectations beforehand.[4] One of the criticisms of mock objects is that there is a tighter coupling of the test code to the system under test.[5] Since Mockito attempts to eliminate the expect-run-verify pattern[6] by removing the specification of expectations, the coupling is reduced or minimized. The result of this distinguishing feature is simpler test code that should be easier to read and modify.&You can verify interactions: &
List mockedList = mock(List.class);
&span class="Apple-tab-span" style="white-space:"&
&/span&mockedList.add("one");
mockedList.clear();
verify(mockedList).add("one");
verify(mockedList).clear();
Or stub method callsLinkedList mockedList = mock(LinkedList.class);
&span class="Apple-tab-span" style="white-space:"&
&/span&when(mockedList.get(0)).thenReturn("first");
&span class="Apple-tab-span" style="white-space:"&
&/span&System.out.println(mockedList.get(0));
&span class="Apple-tab-span" style="white-space:"&
&/span&System.out.println(mockedList.get(999)); A simple example Java code used Mockito&& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & Without Mock framework&& & & & & & & & & & & & & & & & & & & & & & & & & & & & & &With Mockito framework&Step 1:& Create a Maven project in Eclipse&&Define the pom.xml as below :& ="1.0" ="UTF-8"
&pre&&project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&
&modelVersion&4.0.0&/modelVersion&
&groupId&</.phatbeo.ut.mockito.demo&/groupId&
&artifactId&demoMockito&/artifactId&
&version&0.0.1-SNAPSHOT&/version&
&packaging&jar&/packaging&
&name&demoMockito&/name&
&url&http://maven.apache.org&/url&
&properties&
&project.build.sourceEncoding&UTF-8&/project.build.sourceEncoding&
&/properties&
&sourceDirectory&src&/sourceDirectory&
&testSourceDirectory&test&/testSourceDirectory&
&groupId&org.apache.maven.plugins&/groupId&
&artifactId&maven-compiler-plugin&/artifactId&
&version&2.3.1&/version&
&configuration&
&source&1.6&/source&
&target&1.6&/target&
&/configuration&
&/plugins&
&dependencies&
&dependency&
&groupId&junit&/groupId&
&artifactId&junit&/artifactId&
&version&4.8.1&/version&
&scope&test&/scope&
&/dependency&
&dependency&
&groupId&org.mockito&/groupId&
&artifactId&mockito-all&/artifactId&
&version&1.8.5&/version&
&scope&test&/scope&
&/dependency&
&/dependencies&
&/project& Step 2:& Add java source code&&Class Person.java
package vn.com.enclave.phatbeo.ut.mockito.
public class Person
private final Integer personID;
private final String personN
public Person( Integer personID, String personName )
this.personID = personID;
this.personName = personN
public Integer getPersonID()
return personID;
public String getPersonName()
return personN
} &Interface&PersonDAO.java&package vn.com.enclave.phatbeo.ut.mockito.
public interface PersonDao
public Person fetchPerson( Integer personID );
public void update( Person person );
} &Class&PersonService.java& package vn.com.enclave.phatbeo.ut.mockito.
public class PersonService
private final PersonDao personD
public PersonService( PersonDao personDao )
this.personDao = personD
public boolean update( Integer personId, String name )
Person person = personDao.fetchPerson( personId );
if( person != null )
Person updatedPerson = new Person( person.getPersonID(), name );
personDao.update( updatedPerson );
} &Step 3:& Added unit-test class.&&Then, jump to write unit test cases for class PersonService.java&In assumption, class PersionServiceTest.java is as below:package vn.com.enclave.phatbeo.ut.mockito.demo.
import static org.junit.Assert.assertE
import static org.junit.Assert.assertF
import static org.junit.Assert.assertT
import static org.mockito.Mockito.
import static org.mockito.Mockito.verifyNoMoreI
import static org.mockito.Mockito.verifyZeroI
import static org.mockito.Mockito.
import org.junit.B
import org.junit.T
import org.mockito.ArgumentC
import org.mockito.M
import org.mockito.MockitoA
public class PersonServiceTest
private PersonDao personDAO;
private PersonService personS
public void setUp()
throws Exception
MockitoAnnotations.initMocks( this );
personService = new PersonService( personDAO );
public void shouldUpdatePersonName()
Person person = new Person( 1, "Phillip" );
when( personDAO.fetchPerson( 1 ) ).thenReturn( person );
boolean updated = personService.update( 1, "David" );
assertTrue( updated );
verify( personDAO ).fetchPerson( 1 );
ArgumentCaptor&Person& personCaptor = ArgumentCaptor.forClass( Person.class );
verify( personDAO ).update( personCaptor.capture() );
Person updatedPerson = personCaptor.getValue();
assertEquals( "David", updatedPerson.getPersonName() );
verifyNoMoreInteractions( personDAO );
public void shouldNotUpdateIfPersonNotFound()
when( personDAO.fetchPerson( 1 ) ).thenReturn( null );
boolean updated = personService.update( 1, "David" );
assertFalse( updated );
verify( personDAO ).fetchPerson( 1 );
verifyZeroInteractions( personDAO );
verifyNoMoreInteractions( personDAO );
} Points of Interest&&+ What's Mock framework in overview.&+ Why we use Mockito in testing in Java development.&References&&HistoryFirst release on Dec 26, 2012
This article, along with any associated source code and files, is licensed under
Comments and Discussions
General &&
Suggestion &&
Question &&
Admin && Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Last Updated 27 Dec 2012
Article Copyright 2012 by Phat (Phillip) H. VUEverything else
Copyright & ,清天朗日QAS-1(白色)
清天朗日QAS-1(白色) 别名:QAS-1(白色)
>> PART:DetailVer3/Part/Detail/FreeVersionFirstScreen >>> -->
是否多层滤网:
*未认证品牌仅显示部分参数
>> PART:DetailVer3/Part/Detail/ParamPerformance >>> -->
>> PART:DetailVer3/Part/Detail/RelDocV31 >>> -->
购买家电对于很多人来说就像割肉一样疼,因为现在家电动辄就是几十万,而且还是上不封顶,什么价位的都有,让人们头疼不已,低价位的又怕质量不好,可是随着科技的发展,家...
雾霾这两个字大家都不陌生,因为这是我们茶余饭后经常谈论的话题。近几日日,雾霾再次袭来。北京首次启动了空气重污染红色预警。单双号限行,中小学停课,工地甚至停工,这...
大部分人看来,家电的选购是一件极其纠结的事情,其困难复杂程度不亚于装修买房。由于家电市场产品众多,种类纷繁,有的人不清楚到底需要什么样的,到市场一看,眼花缭乱,...
>> PART:DetailVer3/Part/Detail/StarVersionRank >>> -->
>> PART:DetailVer3/Part/Review/ReviewDetail >>> -->
>> PART:DetailVer3/Part/Review/ReviewPosterPart >>> -->
评分表达您的观点
简洁概括您对该产品的感受,分享更多内容,可选择高级点评
哇塞您的点评好用心,去中记录吧!
上传图片(0/9)
基础认证品牌 同产品中50%属于此范围
良好认证品牌 同产品中35%属于此范围
优质认证品牌 同产品中15%属于此范围
认证品牌提升影响力&
版本服务,
金牌置顶服务,
标王服务,
>> PART:DetailVer3/Part/Detail/PossibleInterest >>> -->
>> PART:PluginVer3/Rank/Manu >>> -->
>> PART:DetailVer3/Part/Detail/AdZPlusGoods >>> -->
>> PART:DetailVer3/Part/Detail/LastProTbl >>> -->

我要回帖

更多关于 长谷川 sdf1 的文章

 

随机推荐