在ANDROID STUDIO環境下使用JUNIT架構進行單元測試

來源:互聯網
上載者:User

標籤:ret   arraylist   throws   module   exce   const   單元測試   equals   ack   

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.1.1‘
compile ‘com.android.support.constraint:constraint-layout:1.0.1‘
testCompile ‘junit:junit:4.12‘
}

package com.example.test;

public class Array {

//擷取最大子數組
public int list(int[] list) {
int summax = max(list);
int i, j, k;
for (i = 0; i < list.length; i++)
for (j = i; j < list.length; j++) {
int temp = 0;
for (k = i; k <= j; k++)
temp += list[k];
if (temp > summax) {
summax = temp;
}
}
return summax;

}

//擷取數組的最大值
public int max(int[] list) {
int max = list[0];
for (int i = 0; i < list.length; i++) {
if (max < list[i]) {
max = list[i];
}
}
return max;
}

}

package com.example.test;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class ArrayTest {
private Array mArray;int[] ArrayList = {-2,-3,-5,-1,-9};


@Before
public void setUp() throws Exception {
mArray = new Array();
}

@After
public void tearDown() throws Exception {

}

@Test
public void list() throws Exception {
assertEquals(-1, mArray.list(ArrayList), 0);

}

}

在ANDROID STUDIO環境下使用JUNIT架構進行單元測試

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.