4.junit的使用
首先我们给hello类添加一个abs()方法,作用是返回绝对值
public int abs(int n){
return n>0?n:(-n);
}
选中helloworld.java,右键点击,选择new->junit test case:
eclipse在询问是否添加junit.jar包之后,确定后新建一个helloworldtest类,用来测试helloworld类。
选中setup()和teardown(),然后点击“next”:
选择要测试的方法,在前面打勾.
再在helloworldtest中添加测试代码:
点击run as junit,左侧导航栏切换到junit.如果测试通过,将为绿色显示.
5.添加tomcat应用程序
按照向导完成即可.可以看到在server.xml中增加了如下内容:
<context path="/testapp" reloadable="true" docbase="d:\eclipse\workspace\testapp" workdir="d:\eclipse\workspace\testapp\work\org\apache\jsp" />
如果右击src添加包和类的话,保存后会自动添加到classes中.
右击testapp新建文件index.jsp,添加如下内容:
<%@ page contenttype="text/html;charset=gbk"%>
<html>
<head>
<title>
helloworld
</title>
</head>
<body>
helloworld!
</body>
</html>
然后启动tomcat,在浏览器中输入http://127.0.0.1:8080/testapp/index.jsp,即可看到index的内容了.
