读书人

错误测试DEMO

发布时间: 2012-07-02 17:46:22 作者: rapoo

异常测试DEMO

package com.lijun;import static org.junit.Assert.*;import org.junit.Before;import org.junit.Test;public class Junit4ExceptionTest {private User user;@Beforepublic void init() {user = null;}@Test(expected = NullPointerException.class)public void testUser() {//assertNotNull(user.getUserName());user.getUserName();}}class User {private String userName;public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}}

读书人网 >软件开发

热点推荐