2015-11-06 124 views

回答

1

随着一些猜测,我能够确定几个步骤来获得在iOS上运行的集成测试。不过,我仍然在弄清楚如何让Android集成测试起作用。

继续前进,从RN github上复制IntegrationTests.js并称为Tests.js

将新的JS文件这两个文件在你的项目的根。然后更改IntegrationTests.js,并将它们的所有需求更改为刚刚创建的文件require('./测试')所需的一条语句

以下是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({ 
    shouldResolve: false, 
    shouldReject: false, 
    propTypes: { 
    RunSampleCall: React.PropTypes.bool 
    }, 
    getInitialState() { 
    return { 
     done: false, 
    }; 
    }, 
    componentDidMount() { 
    if(this.props.TestName === "SomeTest"){ 
     Promise.all([this.SomeTest()]).then(()=> 
     { 
     TestModule.markTestPassed(this.shouldResolve); 
     }); 
     return; 
    } 
    }, 
    async SomeTest(){ 
    var one = 1; 
    var two = 2; 
    var three = one + two; 
    if(three === 3){ 
     this.shouldResolve = true; 
    }else{ 
     this.shouldResolve = false; 
    } 
    } 
    render() : ReactElement<any> { 
    return <View />; 
    } 
}); 

Tests.displayName = 'Tests'; 

module.exports = Tests; 

这是一个基本的实现您的Tests.m文件(里面的Xcode)

#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 IntegrationTests : XCTestCase 

@end 

@implementation IntegrationTests 
{ 
    RCTTestRunner *_runner; 
} 

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

- (void)test_SomeTest 
{ 
    [_runner runTest:_cmd 
      module:@"Tests" 
     initialProps:@{@"TestName": @"SomeTest"} 
configurationBlock:nil]; 
} 

@end 

还需要从node_modules添加RCTTest /反应本地/库/ RCTTest/RCTTest的.xcodeproj到你的库。那么您需要将您添加到链接框架和库中的项目的产品libRCTTest.a拖放到常规选项卡中的主目标。

^^这条道路可能会稍有不正确

然后你需要编辑您的方案,并设置环境变量CI_USE_PACKAGER 1

所以,如果你做所有这些步骤,你应该有一个简单的测试运行,通过。之后应该很容易扩展。对不起,如果我的回答略显草率,请告诉我,如果您有任何问题。