package cn.itcast.junit.test;
import java.io.File;
import cn.itcast.junit.service.CalcService;
import android.os.Environment;
import android.os.StatFs;
import android.test.AndroidTestCase;
public class TestCalcService extends AndroidTestCase {
public void testAdd() throws Exception{ // 把程序出现的例外 抛给测试框架
CalcService service = new CalcService();
int result = service.add(3, 5);
assertEquals(9, result);
}
public void testSub() throws Exception{ // 把程序出现的例外 抛给测试框架
CalcService service = new CalcService();
int result = service.sub(3, 5);
assertEquals(-2, result);
}
/**
* 测试类 TestCalcService 在第一次被创建的时候 ,
* 做一些初始化全局变量的操作
*/
@Override
protected void setUp() throws Exception {
super.setUp();
}
/**
* 测试类 TestCalcService 在被销毁的时候 ,
* 做一些擦屁股的操作
*/
@Override
protected void tearDown() throws Exception {
super.tearDown();
}
public void testSDsize() throws Exception{
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long totalBlocks = stat.getBlockCount();
long totalbytes = blockSize*totalBlocks;
System.out.println(totalbytes);
}
}
<pre class="java" name="code">package cn.itcast.junit.service;
public class CalcService {
/**
* 相加的方法
* @param x
* @param y
* @return
*/
public int add(int x ,int y){
int result = x+y;
return result;
}
/**
* 相减的方法
* @param x
* @param y
* @return
*/
public int sub(int x ,int y){
int result = x-y;
return result;
}
}