Gralde – Unit test

Buil test configuration

app > build.gradle 환경 파일을 아래와 같이 수정한다.
instrumentTest.setRoot(‘tests’)라는 거.

android {
... 
  sourceSets {
        main {
            jniLibs.srcDirs = ['libs', 'src/main/libs']
            jni.srcDirs = []
        }
        instrumentTest.setRoot('tests')
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
...
}

##Unit test example file

public class ExampleUnitTest {
...
    @Test
    public void addTest() throws Exception {
        assertEquals(4, 2 + 2);
    }
...
}

이상.

iOS – 유닛 테스트 쉽게 하기! (Swift 2 + XCode 7)

원문

유닛 테스트를 하기 위해 아래의 항목을 확인해주어야 한다.

1. 내부 클래스 만들기

만약 새롭게 내부 클래스를 만들었다면, 클래스나 메서드를 찾지 못한다면, 아래와 같이 Public 처리를 해주어야 한다.

NewImage

2. Import with @testable

테스트 타겟에서, 아래와 같이 @testable keyword를 사용하여, 모듈을 import해줘야한다.

NewImage

3. Test하기

모든게 완료되었다. 외부 클래스나 메서드도 쉽게 테스트 할 수 있다.

NewImage

끝.

Android > Unit Test Functional and UI

These are what i referenced.
– http://stackoverflow.com/questions/16586409/how-can-i-create-tests-in-android-studio

– http://www.vogella.com/articles/AndroidTesting/article.html#activity_testing1

– http://tools.android.com/recent/androidstudio018released

Edit: As of 0.1.8 this is now supported in the IDE.

Following the Android Gradle Plugin User Guide I was able to get tests working on the command line by performing the following steps on a newly created project (I used the default ‘com.example.myapplication’ package):

1. Add a src/instrumentTest/java directory for the tests
2. Add a test class (extending ActivityTestCase) in the package com.example.myapplication.test
3. Start a virtual device
4. On the command line (in the MyApplicationProject/MyApplication directory) use the command ‘../gradlew connectedInstrumentTest’

This ran my tests and placed the test results in MyApplicationProject/MyApplication/build/reports/instrumentTests/connected. I’m new to testing Android apps, but it seem to work fine.