Java单元测试

发表于:2010-9-01 13:50

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

分享:

  assertNotNull(a)

  Asserts that an object isn't null.

  测试a是否非空,a是一个对象或者null。

  assertNull(a)

  Asserts that an object is null.

  测试a是否为null,a是一个对象或者null。

  assertNotSame(a, b)

  Asserts that two objects do not refer to the same object.

  测试a和b是否没有都引用同一个对象。

  assertSame(a, b)

  Asserts that two objects refer to the same object.

  测试a和b是否都引用同一个对象。

  测试代码如下:

package com.topone.saa.test;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;

import java.sql.SQLException;
import static java.lang.Math.*;

import com.topone.saa.Sorting;

public class SortingTest {
private Sorting sort = new Sorting();
@BeforeClass
public static void testBeforeClass(){
}
@Before
public void testBefore(){
System.out.println("@Before.....");
Assume.assumeNotNull(PI);
}
@After
public void tsetAfter(){
}
@AfterClass
public static void testAfterClass(){
}
@Ignore
@Test
public void testSorting(){
int[] arr = {333,231,3,53,23};
sort.bubbleSorting(arr);
sort.selectSorting(arr);
sort.insertSorting(arr);
sort.main(null);
Assert.assertArrayEquals(new int[]{3,23,53,231,333}, arr);
}
@Test(timeout=500)
public void testSortingForNeagtive(){
int[] arr = {-23,-1,-55,-232,-12};
sort.selectSorting(arr);
sort.insertSorting(arr);
sort.bubbleSorting(arr);
//sort.main(null);
Assert.assertArrayEquals(new int[]{-232,-55,-23,-12,-1}, arr);
}
}

33/3<123
精选软件测试好文,快来阅读吧~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号