简体   繁体   English

如何为 AVPlayer 编写单元测试用例?

[英]How to write Unit Test cases for AVPlayer?

We are using AVPlayer and playing DRM Protected content using fairplay approach.我们正在使用 AVPlayer 并使用公平播放方法播放受 DRM 保护的内容。

Now it's time for writing Unit Test cases for the player.现在是为玩家编写单元测试用例的时候了。 I know how to write unit test cases to check API calls, functionality check etc.我知道如何编写单元测试用例来检查 API 调用、功能检查等。

But I'm not able to figure out what are the test cases I can write for AVPlayer to check the player functionality, content quality, audio and video output checks.但我无法弄清楚我可以为 AVPlayer 编写哪些测试用例来检查播放器功能、内容质量、音频和视频输出检查。

I would like to know is it possible to write Unit test cases for a Player ?我想知道是否可以为 Player 编写单元测试用例? if yes, what will be the better way of doing it ??如果是,那么更好的方法是什么?

Any code you write should/can be tested, it may not make much sense to test the audio but in projects with many collaborators, someone can at some point make a change and crashing the application the tests would help you to see that.您编写的任何代码都应该/可以进行测试,测试音频可能没有多大意义,但是在有许多合作者的项目中,有人可以在某些时候进行更改并使应用程序崩溃,这些测试将帮助您看到这一点。 I had the same thoughts as you before I had to write the test cases and that led me to find your question here.在我不得不编写测试用例之前,我和你有同样的想法,这让我在这里找到了你的问题。 I wrote test cases where I needed to test my project's audio layer.我编写了需要测试项目音频层的测试用例。 It may not make much sense, but if you need to present a 100% tested code, it is valid.这可能没有多大意义,但如果您需要提供 100% 测试过的代码,它是有效的。

It's a simple example.这是一个简单的例子。

import XCTest

class AudioPlayerTests: XCTest {

    let audioManager = AudioManager()

    func test_AudioManager_PlaySound() { 
        audioManager.playSound(named: .background, numberOfLoop: 0, volume: 1)
        XCTAssertNotNil(audioManager.audioPlayer)
        XCTAssertEqual(audioManager.audioPlayer!.numberOfLoops, 0)
        XCTAssertEqual(audioManager.audioPlayer!.volume, 1)
        XCTAssertTrue(audioManager.audioPlayer!.isPlaying)
    }

    func test_getaudio() {
        audioManager.playSound(named: .effectOne)
        let sut = audioManager.getSKAudioNode(.background)
        XCTAssertNotNil(sut)
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM