2016-06-23 2 views
0

반응 네이티브 :통합 테스트 반작용 - 기본 인쇄 아이폰 OS가없는 (CONSOLE.LOG)

(전체 보조 노트 : 당신은 설정하는 만 시간이 있다면 위로 통합 테스트는 내가 도와주고 아래 코드를 사용한 다음 계획을 편집하고 실행 인수를 설정하기 만하면된다. UIExplorer 애플리케이션을 점검하여 인수가 무엇인지, 무엇을 설정해야하는지 확인한다. 중요한 대상을 설정해야하며 폴더의 루트에 IntegrationTesting.js 및 Tests.js도 넣으십시오.)

질문으로 돌아 가기 :

https://facebook.github.io/react-native/docs/testing.html

와 나는 세 가지 주요 파일이 있습니다. IntegrationTests.m, IntegrationTests.js 및 Tests입니다. IntegrationTests.m은 다음과 같습니다

#import <UIKit/UIKit.h> 
#import <XCTest/XCTest.h> 

#import <RCTTest/RCTTestRunner.h> 

#import "RCTAssert.h" 

#define RCT_TEST(name)     \ 
- (void)test##name      \ 
{          \ 
[_runner runTest:_cmd module:@#name]; \ 
} 

@interface UIExplorerIntegrationTests : XCTestCase 

@end 

@implementation UIExplorerIntegrationTests 
{ 
    RCTTestRunner *_runner; 
} 

- (void)setUp 
{ 
    _runner = RCTInitRunnerForApp(@"IntegrationTests", nil); 
} 

#pragma mark - Test harness 

- (void)testTheTester_waitOneFrame 
{ 
    [_runner runTest:_cmd 
      module:@"Tests" 
     initialProps:@{@"waitOneFrame": @YES} 
configurationBlock:nil]; 
} 


#pragma mark - JS tests 

// This list should be kept in sync with IntegrationTestsApp.js 
RCT_TEST(Tests) 



@end 

IntegrationTests.js이

'use strict'; 

var React = require('react'); 
var ReactNative = require('react-native'); 
var { 
    AppRegistry, 
    ScrollView, 
    StyleSheet, 
    Text, 
    TouchableOpacity, 
    View, 
} = ReactNative; 

var TESTS = [ 
    require('./Tests'), 
]; 

TESTS.forEach(
    (test) => AppRegistry.registerComponent(test.displayName,() => test) 
); 

// Modules required for integration tests 
// require('LoggingTestModule'); 

type Test = any; 

var IntegrationTests = React.createClass({ 
    getInitialState: function() { 
    return { 
     test: (null: ?Test), 
    }; 
    }, 
    render: function() { 
    if (this.state.test) { 
     return (
     <ScrollView> 
      <this.state.test /> 
     </ScrollView> 
    ); 
    } 
    return (
     <View style={styles.container}> 
     <Text style={styles.row}> 
      Click on a test to run it in this shell for easier debugging and 
      development. Run all tests in the testing environment with cmd+U in 
      Xcode. 
     </Text> 
     <View style={styles.separator} /> 
     <ScrollView> 
      {TESTS.map((test) => [ 
      <TouchableOpacity 
       onPress={() => this.setState({test})} 
       style={styles.row}> 
       <Text style={styles.testName}> 
       {test.displayName} 
       </Text> 
      </TouchableOpacity>, 
      <View style={styles.separator} /> 
      ])} 
     </ScrollView> 
     </View> 
    ); 
    } 
}); 

var styles = StyleSheet.create({ 
    container: { 
    backgroundColor: 'white', 
    marginTop: 40, 
    margin: 15, 
    }, 
    row: { 
    padding: 10, 
    }, 
    testName: { 
    fontWeight: '500', 
    }, 
    separator: { 
    height: 1, 
    backgroundColor: '#bbbbbb', 
    }, 
}); 

AppRegistry.registerComponent('IntegrationTests',() => IntegrationTests); 

Tests.js처럼 보인다는 다음과 같습니다 : 일부

'use strict'; 

var React = require('react'); 
var ReactNative = require('react-native'); 

var { 
    Text, 
    View, 
} = ReactNative; 
var { TestModule } = ReactNative.NativeModules; 

var Tests = React.createClass({ 
    propTypes: { 
    waitOneFrame: React.PropTypes.bool 
    }, 

    getInitialState() { 
    return { 
     done: false, 
    }; 
    }, 

    componentDidMount() { 
    console.log("I'll never see this print statement in the xcode console") 
    this.runTest(); 
    }, 

    runTest() { 

    async function SampleCall(){ 
     try{ 
      console.log("hey whatsup inside async!") 
     }catch(e){ 
      throw new Error("ERROR: " + e); 
      console.log("download failed: " + e) 
     } 
    } 
    SampleCall(); 


    }, 

    render() { 
    return (
     <View style={{backgroundColor: 'white', padding: 40}}> 
     <Text> 
      {this.constructor.displayName + ': '} 
      {this.state.done ? 'Done' : 'Testing...'} 
     </Text> 
     </View> 
    ); 
    } 
}); 

Tests.displayName = 'Tests'; 

module.exports = Tests; 

인쇄 할 수없는 이유 console.log. 비동기 기능으로 인쇄할지 말지에 상관없이 인쇄 할 수 없습니다. 원격 디버거 메서드를 사용하여 시도했지만 이상한 동작이 발생합니다. 나는 인쇄 할 수 있었다 그러나 나의 시험은 휴식이 불평 것 :

  • Make sure Packager server is running.
  • Make sure the JavaScript Debugger is running and not paused on a breakpoint or exception and try reloading again."

을 그리고 네 내 IP 주소로 로컬 호스트 설정을 시도하고 모든 일이 더 많은 현실에서 도피하기 시작했다.

NSString *URLString = [NSString stringWithFormat:@"http://MY.IPA.DDR.ESS:%zd/debugger-proxy?role=client", port]; 

failed: caught "NSInternalInconsistencyException", "RedBox error: Runtime is not ready for debugging.

경우 중 하나 내 CONSOLE.LOG 문 반응 네이티브가 통합 테스트를 설정 한 형식으로 실행 xctests에 Xcode의 콘솔에서 눈에 보이지 않는, 또는 당신은 내가 왜 해요 알고 이유를 알고 원격 디버거를 설정할 수 없으니 도와주세요! 감사합니다

답변

0

로그 및 AVA 테스트에 대해서는 Reactotron을 시도해야합니다. 이 툴로 테스트를하는 것은 현재의 접근 방식보다 훨씬 간단합니다. this은 완료 방법에 대한 몇 가지 예이므로 시간이 많이 절약되었습니다.