关于自动化测试的学习笔记

2018-03-08  本文已影响28人  l蓝色梦幻

Mousepose

屏幕上鼠标位置/按键高亮

关于 LeanCloud 的测试情况

为什么要写单元测试

怎么写单元测试

expecta

框架平息

iOS 单元测试异步处理

#define WAIT(name)                                                          \
do {                                                                        \
    [self expectationForNotification:name object:nil handler:nil];          \
    [self waitForExpectationsWithTimeout:60 handler:nil];                   \
} while(0)

#define NOTIFY(name)                                                            \
do {                                                                            \
    [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil];\
} while(0)     


- (void)waitNotification:(const void *)notification {
    NSString *name = [NSString stringWithFormat:@"%p", notification];
    [self expectationForNotification:name object:nil handler:nil];
    [self waitForExpectationsWithTimeout:AV_YEAR_SECONDS handler:nil];
}

- (void)postNotification:(const void *)notification {
    NSString *name = [NSString stringWithFormat:@"%p", notification];
    [[NSNotificationCenter defaultCenter] postNotificationName:name object:nil];
}

覆盖率

从 Xcode7 开始,自带覆盖率高爆功能. 设置要点:

  1. Scheme 中开启 Gather Coverage Data
  2. 针对 App Target 来测试, 而非 Test Target
  3. We've Got You Covered
  4. 如何查看单元测试具体运行需要了解哪些代码
覆盖率.png

Xcode 7 之后的脚本

xcodebuild                          \
    -workspace AVOS.scworkspace     \
    -scheme AVOSCloudIMTests        \
    -sdk iphonesimulator            \
    clean                               \
    test &&                         \
xcodebuild                          \
    -workspace AVOS.scworkspace     \
    -scheme AVOSCloudTests          \
    -sdk iphonesimulator            \
    clean                               \
    test                                \

远程自动化测试

Jenkins 配置

export LC_ALL="en_US.UTF-8"
pod install --verbose --no-repo-update
if [ -e test.sh] then 
    ./test.sh
fi

Jenkins 如何知道测试失败或者成功

Travis CI

travis-ci

language: objective-c
xcode_workspace: XXX.xcworkspace
xcode_scheme: XXX

远程打包发布

实现思路

execute_command('security unlock-keychain -p "xxx" ~/Library/Keychains/login.keychain')

在命令行中解Keychain, 一般会弹框输入密码

Lioo

Pod

自动化 Pod 推送

def push_podspec_in_path(path)
    iterate_r(path, 'podspec') do |file|
        podspec_name = File.basename(file, ".podspec")
        podspec_version = version[1..-1]
        exists = is_podspec_exists(podspec_name, podsepc_version)
        if exists
            log("#{podspec_name} #{podsepc_version} exists!")
            next
        else 
            log("#{podspec_name} #{podsepc_version} not exists, now try to push it")
        end
        
        ok = false
        for i in 0..10
            ok = system("pod truck push #{file} --verbose --allow-warning")
            if ok
                log("success to push #{file}")
                break
            else 
                log("failed to push #{file}")
            end
        end
        
        if !ok
            exit_with_info("")
        end
    end
end

重复推送 Podspec

def is_podspec_exists(name, version)
    podspec_url = "https://github.com/CocoaPods/Specs/blob/master/Specs/#{name}/#{version}/#{name}"
    url = URI.parse(podspec_url)
    req = Net::HTTP::Get.new(url.to_s)
    http = Net::HTTP.new(url.host, url.port)
    http.use_ssl = true
    res = http.request(req)
    res.code == '200'
end

好用的工具

上一篇下一篇

猜你喜欢

热点阅读