Skip to content

Instantly share code, notes, and snippets.

@sendz
Last active October 29, 2016 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sendz/b366d23534e482b4099483f82bf693dc to your computer and use it in GitHub Desktop.
Save sendz/b366d23534e482b4099483f82bf693dc to your computer and use it in GitHub Desktop.
Hitung Luas Unit Test
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "io.github.sendz.distanceconverter"
minSdkVersion 22
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
testCompile 'junit:junit:4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.2.3'
}
package io.github.sendz.hitungluas;
import org.junit.Before;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
public class MainPresenterTest {
private MainPresenter presenter;
private MainView view;
@Before
public void setUp() throws Exception {
view = mock(MainView.class);
presenter = new MainPresenter(view);
}
@Test
public void testHitungLuasPersegi() throws Exception {
int luas = presenter.luasPersegi(4, 3);
assertEquals(12, luas);
}
@Test
public void testHitungLuasDanCekApakahHasilDitampilkanDiActivity() throws Exception {
presenter.hitungLuas(4, 3);
verify(view).tampilkanLuas(any(MainModel.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment