current position:Home>Experience of IOS interview strategy - App testing and launching

Experience of IOS interview strategy - App testing and launching

2022-06-24 12:44:20Programmers who can write bugs

Many programmers finish their development , What I expect most is that the simulator can run through the last time , Then you can hand over the work . Actually, it's professional iOS In addition to a very thorough plan before development , Various details and boundary conditions shall be considered in the development , A lot of tests will be done after development .

In my opinion, there are three kinds of tests . The first is common unit testing 、UI test 、 Performance testing , A lot of integration tests will even be done for a certain module , Such tests basically test all possible logical vulnerabilities in the software . The second test is the real machine test , Generally, large companies will be equipped with professional QA To manually test various situations , The first test that is difficult to cover and some cases that must be tested by real hardware belong to this kind of test . The third test is to put App Of beta The version is in Testflight Internal test on , This test will invite specific users to experience , For final function verification . At Silicon Valley , Testing has always been seen as part of the routine work of engineers , Even some companies have adopted the method of writing code based on tests TDD(Test Driven Development) Pattern . Unfortunately , For a variety of reasons , At present, domestic Internet companies mainly rely on QA complete .

We as professional iOS developer , Although there is no need to master testing skills in depth , But at least you should understand the importance of testing , And can complete the basic test operation independently . In ensuring that App Safe and secure 、 Similar in the future bug No more recidivism , The effect of the test is irreplaceable .

After completing the test , It doesn't mean App You can certainly enter the store through Apple's approval . Apple has official guidelines for auditing . This section also selects common App Store Related Uploads 、 download 、 Discuss the audit issues .

Test related

1. One App collapsed , What may have caused it ?

key word :# Code # Memory # The Internet # The third party

  • Code error . Take advantage of Objective-C Dynamic performance of , No errors will be reported at compile time , As a result, the program cannot find the corresponding implementation after running , There's a breakdown . Here's an example .
// o1  and  o2  There are implementation methods  myMethod, however  o3  No, 
MyObject *o1 = ...
MyObject *o2 = ...
NSObject *o3 = ...

NSArray *array = @[o1, o2, o3];
for (id obj in array) {
  [obj meMethod];
}

// Runtime error: unrecognized selector sent to instance XXX
  • Out of memory . such as App It takes up a lot of memory of the mobile phone during operation , here App It will collapse . It often occurs in phones with low configuration or small memory capacity . This problem can be solved by Xcode Instruments Debug and judge .
  • Network reasons . When the network is poor ,App The timeout caused by the request of not getting an immediate response ; Or there are too many users , The server is overloaded and the mobile phone crashes . In fact, these can improve the user experience in optimizing server-side configuration and handling mobile side exceptions .
  • The third party . The third-party tools used in the development may have viruses or bug. In addition, the pop-up of advertisements may also block threads or occupy memory , Lead to App collapse .

The general solution is App The way to crash is to check the corresponding machine log . The mainstream detection tools abroad are twitter Development 、google Maintenance of Fabric. The mainstream tool in China is Tencent Bugly.

2. After completing all tests on the simulator , Whether there is no need to test on the real machine ?

key word :# function # Hardware

The answer is , Whether or not you need a real test depends on the specific situation . The simulator can complete most of the function tests . But there are still differences between real machines and simulators , Mainly focus on function and hardware :

  • Functional aspects . Simulator does not support Email、 conversation 、 SMS and other functions , At the same time, it does not support Accessibility Of VoiceOver function , If App It is used by the disabled , Please be sure to test on the real machine .
  • Hardware aspect . The simulator does not support cameras 、 Audio input 、 Bluetooth and other hardware functions . If App Support bracelets such as Apple Watch linkage , Please be sure to test on the real machine .

If App These differences are not involved , In theory, there is no need to test with a real machine . Of course, be cautious , If you have enough time, you must test the main functions on the real machine .

3. Why is it necessary to use... To introduce code modules into unit tests  @testable  key word ?

key word :#internal

When testing , We often need to import the module. ordinary import module Although the import is complete , But you can only call module Of public Variables and methods .

Unit tests and UI In the test , quite a lot public The method is the integration of multiple internal methods , Instead of testing complex public Method , It's better to test the composition of small internal Method .

At this point, if you can call module Medium internal Variables and methods , It will be very convenient to test .@testable import  It means ,module Medium internal Variables and methods can also be used in tests .

4. Code combat : Try to write the corresponding unit tests for the following methods

key word :# asynchronous #mock

func loadContent() {
  let url = "https://app-info.rtf"
  let session = URLSession.shared
  let client = HTTPClient(session: session)

  client.get(url: url) {(data, error) in
    if let error = error {
      print("Error: \(error)")
      return
    }

    if let data = data {
      print("Data is successfully fetched from server")
    }
  }
}

The above code , Is a method to access the data returned from the server . If this question is used to test , It involves two knowledge points : The first is how to test asynchronous access , The second is to use mock. Let's explain separately .

First , How to test asynchronous access . use expectation . In this question we have set expectation The middle network end will return data, Then call... In an asynchronous thread fulfill() Method , That is, it will be triggered when the asynchronous ends successfully . Then we wait for the asynchronous end , Of course, we will set the timeout threshold .

secondly , Why use mock. In the test , It is impractical to access the server and receive the data return : First, if the server interface is actually called during the test , You can't guarantee what data the server returns , Will you make a mistake , It is impossible to accurately test various situations ; secondly , The calling interface involves real server logic , Will modify the server data , This is obviously not necessary for testing ; Last , It takes time to return data every time you access the server , So the whole test efficiency is very poor . So we can simulate the process of the server returning data , Use a fake client Go to “ Put on an act ” To access the server side , And return the determined data directly from the local . At this point, the whole operation does not really need to rely on the network , And we can conduct simulation tests on various return situations .

Here is the sample code :

var dataLoaded: Data?

func test_loadContent_shouldReturnData() {
  let url = "https://app-info.rtf"
  let session = MockSession()
  let client = HTTPClient(session: session)

  //  use NSPredicate To filter the conditions , Only dataLoaded Not for nil Will be recorded 
  let pred = NSPredicate(format: "dataLoaded != nil")
  let exp = expectation(for: pred, evaluateWith: self, handler: nil)

  client.get(url: url) { [weak self] (data, error) in
    self?.dataLoaded = data
    //  Triggered when the asynchrony ends successfully expectation
    exp.fulfill()
  }
  //  wait for expectation Be triggered , The timeout is set to 5 second 
  wait(for: [exp], timeout: 5.0)
  //  Judge expectation After departure dataLoaded If not for nil, Otherwise the test fails 
  XCTAssertNotNil(dataLoaded, "No data is received!")
}

5. Talk about iOS Performance testing in (performance test)?

key word :# Time consuming #scheme

So called performance testing , Is to test the speed of a method . We usually set a base value , such as 0.01s, Then run a performance test , After the test, the test time and average running time will be displayed . You can compare it with the base value , And set the maximum upper limit , such as 10%. So if the test exceeds the maximum upper limit, it will take time , such as 0.01s * 1.1 = 0.011s, Then the test failed . An example of a performance test is shown below :

image

Performance testing is generally used to analyze methods that may be time-consuming . For example, access operations on the device 、 Network side request 、 Complicated calculations and so on .

Pay attention to performance testing and Instruments Different performance optimizations , The former is App The bottom line of performance : If the time standard for performance test is not met , Then the user experience will be greatly affected , Even rejected by apple . The latter is the icing on the cake optimization operation in terms of performance , Is a task that can improve the user experience . Performance optimization is sometimes not done , It doesn't hurt . Performance testing requires that the method must meet the specified time-consuming requirements .

In general , It is suggested that a special scheme To run performance tests . In this way, it can be clearly related to unit tests or UI Tests distinguish , Borrow shortcut keys cmd+U It is also more convenient to run performance tests alone .

6. Talk about iOS Medium UI test ?

key word :#record #XCUIElement #Identifier #iPhone vs. iPad

First UI The special thing about testing is . We don't need complete handwritten code ,Xcode Of record The function can automatically generate UI Test code . We just need to give the judgment conditions and code optimization .

secondly UI The test of API There are a few noteworthy .XCUIApplication The corresponding instance is the application entry , Secondly, all of them UI Controls are all XCUIElement.UI Tests are based on their corresponding title Property to specify ( If there is title Duplicate names , select XCTest The first Correspondence found by the framework UI Control room ). Of course we can also pass accessibility Identifier To designate a UI Control . So we usually UI Tests are done through concrete actions ( Click on 、 slide ) After that, the comparison is different UI The state of the control , XOR is to look for a specific page to appear UI Control to test .

Last UI The test will involve different sizes of different machines . such as iPhone It's using tableView and iPad It's using splitView, because UI Different layout ,UI Control position differences also need special treatment .

UI Testing focuses more on user behavior / Experience , Unit tests focus on the logical correctness of a single method .UI Tests can cover parts that unit tests cannot cover , for example :

  1. Given the input , The output passed the unit test ; But in fact, the output format does not meet the requirements , The screen will also be indented due to size problems . It's time to UI Test to check .
  2. The keyboard will pop up for no reason in a certain interface but cannot be stowed . At this point, the program is logically correct , Unit testing is no problem ; However UI The test can detect something on the screen UI The control cannot be clicked because it is blocked by the keyboard .

7. How to check test coverage ?

key word :#coverage

After running the test , Switch to log navigation , Click on the test result just now , Click... On the navigation bar Coverage The following test coverage diagram can be obtained :

image

We can not only view the whole App Test coverage of , You can also view the test coverage of each file . Click a file to enter it , The red part indicates the places not covered by the test .

The higher the code coverage, the more perfect the test . Of course we don't have to pursue 100% Code coverage . Note that test coverage is generally used to run all units 、 performance 、UI The data after the test shall prevail .

App Store relevant

8. What is? iOS Medium App ID?

key word :#teamid #bundleid

every last App There are independent ones ID To make sure that , This is it. App ID. It consists of two parts :Team ID and Bundle ID. The two are distinguished by dots , Put together is App ID In the form of :Team ID.Bundle ID.

Team ID Appoint App It is developed by a specific developer or team .Bundle ID Appoint App Or a series of related App.Bundle ID It's only certain App.

Bundle ID Is in Xcode Determined in the project . A single Xcode The project may have multiple target files , Correspondence may also produce multiple App. such as beta Version and pro edition , Paid version, free version, etc .

9. What is? iOS Medium Code Signing?

key word :# The key # Security

In order to determine App Who developed it , Has it been modified after development ,Apple The introduction of Code Signing The mechanism of .

With it , In from App Store download App after ,iOS and MacOS The system can confirm by signature who developed App, And whether the signature is valid .

as long as App The corresponding executable file is modified , The signature is deemed invalid . For invalid signatures, the system will refuse to run App, To ensure the security and user experience of the whole system .

Code Signing The corresponding signature consists of a pair of public and private keys , And a Apple The certificate issued constitutes . The private key is used to generate the signature ; The certificate contains the public key and thus identifies App The developer of the .

10. What is? iOS Medium App Thinning?

key word :# Minimum

App Thinning , Chinese translation for “ Apply slimming ”, refer to App store And the operating system in the installation iOS perhaps watchOS Of App When the optimization through some columns , Minimize the size of the installation package , bring App To save the most resources 、 The most appropriate size is installed on your device . There are three types :slicing, bitcode, and on-demand resources.

  • Slicing It refers to different equipment ,App Corresponding versions are generated . Such as iPad The version contains only iPad Version of the image resources and layout code ,iPhone The version is similar to . Download now App When , Just download the corresponding version of App that will do .
  • Bitcode It's a llvm compile App Intermediate form generated by . Upload or download a new version of App when , Apple will target Bitcode The contained information is added or filtered pertinently , Instead of completely submitting or downloading a new App. stay iOS It is optional in , stay WatchOS in Bitcode It is necessary .
  • On-Demand Resources Is only part of the App Content , As long as it is sufficient to meet its basic operation . Like some games App, Only the original content can be run after the initial download , Not the whole thing . If players are interested in continuing to explore ,App Store Will unlock subsequent content , Download and update it to the game .

11. towards App Store Submit App What are the possible reasons for rejection ?

key word :# collapse # The third party # Copyright # The materials are incomplete

App Store Although the audit of is now faster and faster , The cost of rejection is getting lower , But do it before submitting App Check carefully before , Try to get through at one time , Is still iOS Basic qualities of developers .

There are many reasons for rejection , The main ones are as follows :

  • collapse . The program itself has bug、 Any third-party server error is possible . Note that our usual test is running in an offline environment App, and App Store Is running in an online environment . So when submitting for review , Or you should run on the online environment just in case .
  • The third party . Such as App Third party applications need to be installed , Such as the need to QQ Sign in , And the tester's cell phone doesn't contain QQ, If prompted, install QQ, May be rejected ; In addition, use third-party advertising , It is also possible to be rejected for violating the rules .
  • Copyright . For example, the third-party client applies the name of a platform ;App Describe or name some irrelevant keywords in order to click and rank ; Or is it ready-made App act ;App The content contained in the document without authorization is also the reason for rejection . Note that Apple has certain key words ( such as Android) Very sensitive , Never appear in App In the submission of .
  • The materials are incomplete . Sometimes App Will be caused by lack of materials App Store Cannot audit . For example, missing screenshots or using wrong screenshots ; Hardware related App When submitting , There is no official hardware , At this point, developers need to provide relevant videos .

The above is only part of the case . Apple officially has a special review guide file (App Store Review Guidelines)

, It is recommended that developers upload App You should read it carefully before , And check them one by one .

This is the end of the article , Thanks for watching , I just want to say something to the readers :

iOS There are fewer and fewer developers , Frankly speaking , Every time I see some readers' responses in the background, I feel very happy , At least you still stick to it iOS Technical post … To thank readers , I would like to contribute some of my collection of programming dry goods to you , Give back to every reader , I hope I can help you .

Dry goods mainly include :

① iOS Popular books that must be read in advanced development ( Classic must see )

② iOS Develop advanced technology teaching videos

③ BAT And so on iOS The real question of the interview + answer .PDF file

④ iOS Senior interview in development " Resume production " Guidance video

If you can use it, you can take it ; How to get , Please turn to - my GitHub

my :GitHub Address

copyright notice
author[Programmers who can write bugs],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/175/20210526171258205z.html

Random recommended