2016-09-10 2 views
3

과 수용 테스트에서 서비스, 엠버 2.7.0와 this is the accepted answer for mocking a service in an acceptance test모의 엠버 엠버 이전 버전 2.7.0

, 나는 위의 대답에 따라의 startApp를 호출 할 수 없습니다입니다. 그러나 몇 가지 빠른 테스트를 통해 서비스를 주입하는 데는 문제가 없습니다.

import Ember from 'ember'; 
import { module, test } from 'qunit'; 

let speakerMock = Ember.Service.extend({ 
    speak: function() { 
    console.log("Acceptance Mock!"); 
    } 
}); 

module('Acceptance | acceptance demo', { 
    beforeEach: function() { 
    // the key here is that the registered service:name IS NOT the same as the real service you're trying to mock 
    // if you inject it as the same service:name, then the real one will take precedence and be loaded 
    this.application.register('service:mockSpeaker', speakerMock); 

    // this should look like your non-test injection, but with the service:name being that of the mock. 
    // this will make speakerService use your mock 
    this.application.inject('controller', 'speakerService', 'service:mockSpeaker'); 
    } 
}); 

test('visit a route that will trigger usage of the mock service' , function(assert) { 
    visit('/'); 

    andThen(function() { 
    assert.equal(currentURL(), '/'); 
    }); 
}); 

내가 누락 된 것이 있습니까? 의심스러운 점이 있습니다.

a) 이유가 궁금 하신가요? Embers 문서 provide excellent documentation on stubbing services in components.

b) 수용 테스트에서 서비스를 모의하기를 권장하지 않으십니까? 왜? the guide 가입일

+1

@ykaragol의 대답은 정확합니다. 일반적으로 블랙 박스 기술로 수락 테스트를하는 것이 좋습니다. 그걸로 무엇을 이루고 싶습니까? 어쩌면 우리는 더 적절한 방법을 찾을 수 있습니다. –

답변

1

:

수락 테스트는 테스트 사용자 상호 작용 및 응용 흐름에 사용된다. 테스트는 양식 필드를 채우고 버튼을 클릭하는 등의 작업을 수행하여 사용자와 동일한 방식으로 애플리케이션과 상호 작용합니다. 수락 테스트는 프로젝트 내의 기능이 기본적으로 기능을하며, 프로젝트의 핵심 기능을 되풀이하지 않고 프로젝트의 목표 인 이 충족되는지 확인하는 데 유용합니다.

"명확하게"언급되지는 않았지만 "수용 테스트는 실제 응용 프로그램과 동일하게 작동합니다". 그래서 당신은 뭔가를 조롱하면 안됩니다.

+1

이것은 아마도 맞을 수도 있지만, 환경 테스트를 통해 수용 테스트가 바람직한 중요한 경우가 있습니다. 예를 들어 a/b 테스트를 위해 서비스를 사용하고 테스트를 위해 특정 실험 그룹으로 잠그고 싶습니다. – AlexMA