strictmock 순서 검사는 기본적으로 활성화되어 있지만 멋진 모의에서는 그렇지 않습니다. 정확히 "주문 확인"이 의미하는 바를 얻지 못했습니다. 당신이 다음 bar()
에 전화를 기대하는, foo()
에 대한 호출을 기대하는 모의 말해, 실제 통화가 bar()
다음 foo()
경우EasyMock.createStrictMock (클래스 <T>x)과 EasyMock.createNiceMock (클래스 <T>x)의 차이점
4
A
답변
10
는 엄격한 모의 불평하지만 멋진 모의은하지 않습니다. 그것이 순서 확인의 의미입니다.
0
EasyMock.createStrictMock()은 모의 객체를 만들고 모의 작업이 수행 될 때 모의 메소드 호출 순서를 처리합니다. Click here for complete tutorial.
@Before
public void setUp(){
mathApplication = new MathApplication();
calcService = EasyMock.createStrictMock(CalculatorService.class);
mathApplication.setCalculatorService(calcService);
}
@Test
public void testAddAndSubtract(){
//add the behavior to add numbers
EasyMock.expect(calcService.add(20.0,10.0)).andReturn(30.0);
//subtract the behavior to subtract numbers
EasyMock.expect(calcService.subtract(20.0,10.0)).andReturn(10.0);
//activate the mock
EasyMock.replay(calcService);
//test the subtract functionality
Assert.assertEquals(mathApplication.subtract(20.0, 10.0),10.0,0);
//test the add functionality
Assert.assertEquals(mathApplication.add(20.0, 10.0),30.0,0);
//verify call to calcService is made or not
EasyMock.verify(calcService);
}
EasyMock.createNiceMock() : 예를 아래에 고려 여러 방법이 같은 기능이있는 경우, 우리는 NiceMock 객체를 생성 만 1 예상 (방법) 및 여러 어설 (방법 항목)를 만들 수 있습니다 만들 수 있습니다 주장 (방법 2), ...
@Before
public void setUp(){
mathApplication = new MathApplication();
calcService = EasyMock.createNiceMock(CalculatorService.class);
mathApplication.setCalculatorService(calcService);
}
@Test
public void testCalcService(){
//add the behavior to add numbers
EasyMock.expect(calcService.add(20.0,10.0)).andReturn(30.0);
//activate the mock
EasyMock.replay(calcService);
//test the add functionality
Assert.assertEquals(mathApplication.add(20.0, 10.0),30.0,0);
//test the subtract functionality
Assert.assertEquals(mathApplication.subtract(20.0, 10.0),0.0,0);
//test the multiply functionality
Assert.assertEquals(mathApplication.divide(20.0, 10.0),0.0,0);
//test the divide functionality
Assert.assertEquals(mathApplication.multiply(20.0, 10.0),0.0,0);
//verify call to calcService is made or not
EasyMock.verify(calcService);
}
관련 문제
- 1. Kerberos TGT 동작
- 2. CAS : TGT 복호화
- 3. CAS 서버 TGT 쿠키를 어떻게 보호해야합니까?
- 4. 서비스 주체를 사용하여 TGT 가져 오기
- 5. 연산자 <<() 템플릿 클래스
- 6. 루비 클래스 << 자기
- 7. 클래스 <?>과 클래스 <Object> (Java)의 차이점
- 8. Windows에서 Kerberos TGT 세션 키를 모두 0으로 만들 수있는 이유
- 9. Kerberos (TGT) 티켓 부여 티켓 전달. 더블 홉 구현이 안전합니까?
- 10. SSH/기타 응용 프로그램 용 Java에서 얻은 TGT 사용
- 11. Guice : bind 클래스 <?> to 클래스 <?>
- 12. 클래스, 모듈, 및 클래스 << 자기 방식을 이해하지
- 13. 표기법 "클래스 <?> ..."
- 14. 자바 클래스 <? .NET
- 15. 클래스 A와 클래스 1의 차이점
- 16. 라인 "클래스 클래스 이름 <자료는"
- 17. 클래스 << 내에서 범위를 동적으로 정의
- 18. 정의 연산자 << 내부 클래스
- 19. Ruby 클래스 << Klass = Module :: new
- 20. 루비의 클래스 << 자기가 무엇
- 21. << 연산자 및 상속 된 클래스
- 22. 연산자 << 가상 클래스 사용
- 23. # <# <클래스 : 0xa8930c8> : 0xa578cf8>
- 24. C++ : 연산자 << 중첩 된 클래스
- 25. <? PHP와 <? php의 차이점
- 26. 차이점/* <! [CDATA [*// // <! [CDATA [
- 27. <<와 =의 차이점
- 28. 은 <클래스 '범위'>
- 29. 새 클래스() {...}와 새 클래스 {...}의 차이점
- 30. 클래스 영역과 힙의 차이점