210512 Wed

Sunny·2021년 6월 2일
0

Today I Learned

목록 보기
53/88

1. 첫 번째 학습 내용: 컴파일 타임 vs. 런타임

컴파일 타임 vs. 런타임
개발자는 프로그램이 어떻게 작동할지에 대한 소스코드를 입력한다.
이 소스코드는 컴파일(Compile)과정을 통해 사용자가 실행가능한 프로그램이 되는데 이 컴파일 되는 과정을 컴파일 타임(compile time)이라고 부른다.

컴파일된 프로그램은 사용자로부터 실행되어지는데 이 응용프로그램이 실행되는 과정을 런타임(runtime)이라고 한다.

Compile-time and Runtime are the two programming terms used in the software development. Compile-time is the time at which the source code is converted into an executable code while the run time is the time at which the executable code is started running.

참고 자료
컴파일 타임(Compiletime) 과 런타임 (Runtime)의 차이
Compile time vs Runtime

2. 두 번째 학습 내용: Lazy Loading

0.Overview

사용자가 웹 페이지를 열면 전체 페이지의 내용이 다운로드 되어 단일 이동으로 렌더링이 됩니다.

이를 통해 브라우저는 웹페이지를 캐시할 수 있지만 사용자가 다운로드한 모든 콘텐츠를 실제로 볼 수 있다는 보장은 없습니다.

예를 들어 전체 사진 갤러리를 다운로드했지만 사용자가 첫번째 이미지만 본 후 사용자가 떠났을 때 웹페이지에서는 메모리 및 대역폭 낭비로 인해 발생합니다.

페이지에 액세스할 때 모든 콘텐츠를 대량으로 로드하는 대신 사용자가 필요한 페이지의 일부에 액세스할 때 콘텐츠를 로드할 수 있습니다.

lazy loading을 사용하면 페이지가 placeholder 콘텐츠로 작성되며, 사용자가 필요할 때만 실제 콘텐츠로 대체됩니다.

Q. 무엇이며 어떻게 적용이 되는가?

lazy loading은 페이지를 읽어들이는 시점에 중요하지 않은 리소스 로딩을 추후에 하는 기술입니다. 대신에 이 중요하지 않은 리소스들은 필요할 때 로드가 되어야 합니다.

이미지와 관련된 경우에는 중요하지 않은 리소스들은 "off-screen"와 함께 동기화가 됩니다.

누군가가 웹페이지(이미지, 비디오 등)에 리소스를 추가할 때, 리소스는 small placeholder를 참조합니다. 사용자가 웹페이지를 검색할 때 실제 리소스는 브라우저에 의해 캐시되고 리소스가 사용자 화면에 표시될 때 placeholder를 대체합니다.

예를 들어, 사용자가 웹페이지를 로드하고 즉시 남겨 두면 웹페이지의 맨 위 부분 이외의 항목이 로드되지 않습니다.

이미지, 비디오를 그냥 로딩하지 않고 lazy loading을 사용하는 이유는 사용자가 볼 수 없는 것들을 로딩할 가능성이 있기 때문입니다.

  • 사용자가 보고 있지 않은 것들을 로딩할 때 데이터가 낭비됩니다. 무제한 요금제를 사용하는 사용자인 경우에는 상관이 없지만 제한된 요금제를 사용하는 사용자인 경우 사용자가 보고 있지 않은 화면을 로딩하는 것은 자원(돈)을 낭비할 수도 있습니다.
  • 미디어 리소스를 다운로드 한 후 브라우저는 이를 디코딩하여 화면에 렌더링 해야 합니다.

출처
Lazy Loading 이란?

3. 세 번째 학습 내용: 유닛 테스트

Framework

XCTest

Create and run unit tests, performance tests, and UI tests for your Xcode project.

Use the XCTest framework to write unit tests for your Xcode projects that integrate seamlessly with Xcode's testing workflow.

Tests assert that certain conditions are satisfied during code execution, and record test failures (with optional messages) if those conditions aren’t satisfied. Tests can also measure the performance of blocks of code to check for performance regressions, and can interact with an application's UI to validate user interaction flows.

Framework XCTest

@testable

When you add the @testable attribute to an import statement for a module compiled with testing enabled, you activate the elevated access for that module in that scope. Classes and class members marked as internal or public behave as if they were marked open. Other entities marked as internal act as if they were declared public.

Test swift 파일

  • internal으로 선언되면 접근 원래는 불가능
  • testable을 통해 접근가능

**Article

Defining Test Cases and Test Methods**

Add test cases and test methods to a test target to confirm that your code performs as expected.

Overview

Add tests to your Xcode project by writing one or more test methods, each of which verifies a specific aspect of your code. Group related test methods into test cases, each of which is a subclass of [XCTestCase](https://developer.apple.com/documentation/xctest/xctestcase).

To add tests to your project:

  • Create a new subclass of XCTestCase within a test target.
  • Add one or more test methods to the test case.
  • Add one or more test assertions to each test method.

A test method is an instance method on an XCTestCase subclass, with no parameters, no return value, and a name that begins with the lowercase word test. Test methods are automatically detected by the XCTest framework in Xcode.

class TableValidationTests: XCTestCase {
    /// Tests that a new table instance has zero rows and columns.
    func testEmptyTableRowAndColumnCount() {
        let table = Table()
        XCTAssertEqual(table.rowCount, 0, "Row count was not zero.")
        XCTAssertEqual(table.columnCount, 0, "Column count was not zero.")
    }
}

Tip
To help clarify the organization of your tests, give each test case a name that summarizes the tests within it, such as TableValidationTests, NetworkReachabilityTests, or JSONParsingTests.
To help identify failing tests, give each test method a name that makes it clear what is tested by that method, such as testEmptyTableRowAndColumnCount(), testUnreachableURLAccessThrowsAnError(), or testUserJSONFeedParsing().
팁) test case나 테스트되는 메소드 네임 만으로 아! 이 아이는 무엇을 테스트하기 위한 용도구나~

이름만 봐도 분명하게 이해될 수 있게 네이밍을 해줘야 함!

OpenMarketTests은 Open Market의 무엇을 테스트하겠다는 건지 모호하지 않을까...? 🤔
(JSON 데이타를 제대로 파싱해오는지를 테스트하는거라면 차라리 OpenMarketJSONParsingTests으로 바꾸는게 나을지도?)
고민해봐야겠다!

Asserting Test Conditions

You can check (or assert) conditions inside test methods to make sure that your code is behaving as expected. Use the XCTAssert family of functions to check for Boolean conditions, nil or non-nil values, expected values, and thrown errors.

For example, Listing 1 above uses the XCTAssertEqual(_:_:_:file:line:) function to assert that two integers have the same value.

SUT(system under test): 테스트 하기 위한 주요 객체(primary object)

Instance Method
setUpWithError()

Provides an opportunity to reset state and to throw errors before calling each test method in a test case.

Before each test begins, XCTest calls setUpWithError(), followed by setUp(). If state preparation might throw errors, override setUpWithError(). XCTest marks the test failed when it catches errors, or skipped when it catches XCTSkip.

Understanding Setup and Teardown for Test Methods

Prepare initial state before tests run, and perform cleanup after tests complete.

  • Override the setUpWithError() instance method to set initial state and handle associated errors before each test method is run.
  • Override the tearDownWithError() instance method to perform cleanup and handle associated errors after each test method completes.

→ override 붙인 이유는 customize하려고!

class SetUpAndTearDownExampleTestCase: XCTestCase {

	override func setUpWithError() throws { // 2.
        // This is the setUpWithError() instance method.
        // It is called before each test method begins.
        // Set up any per-test state here.
  }

	override func tearDownWithError() throws { // 10.
        // This is the tearDownWithError() instance method.
        // It is called after each test method completes.
        // Perform any per-test cleanup here.
  }
}

Class
NSDataAsset

An object from a data set type stored in an asset catalog.

Initializing the Data Asset
[init?(name: NSDataAssetName)](https://developer.apple.com/documentation/uikit/nsdataasset/1403439-init)

Initializes and returns an object with a reference to the named data asset in an asset catalog.

Testing in Xcode - WWDC 2019
→ 이건 unit test의 기본적인 사용법부터 차근차근 알려줌

Engineering for Testability - WWDC 2017
→ 이 영상은 유닛 테스트를 어떻게 하면 좀 더 효율적으로 할 수 있을지 접근법을 알려줌 (프로토콜, 익스텐션 이용)

물론 둘다 다보진 않음

PPT하고 앞에 부분만 훑어봄 ..

iOS 유닛 테스트를 배워보자!(1)
iOS Unit Testing and UI Testing Tutorial

profile
iOS Developer

0개의 댓글