??xml version="1.0" encoding="utf-8" standalone="yes"?>
HTML 事g
HTML 声明
w3school 在线教程
]]>
]]>
现在假设我的eclipse安装目录是D:"eclipseQ待安装插g目录是D:"plug-in Q我要安装LanguagePackFeatureQ语a包)(j)、emf-sdo-xsd-SDK、GEF-SDK、Lombozq四个插件?/p>
先把q四个插件程序全部放在D:"plug-in目录里,分别解压。如Lomboz3.0.1.zip解压成Lomboz3.0.1目录Q这个目录包含一 个plugins目录Q要先在Lomboz3.0.1目录中新Z个子目录eclipseQ然后把plugins目录Ud到刚建立的eclipse目录 中,即目录结构要是这L(fng)QD:"plug-in"Lomboz3.0.1"eclipse"plugins
Eclipse
会(x)到指定的目录下去查找 eclipse"features 目录和eclipse"plugins
目录Q看是否有合法的功能部g和(或)(j)插g。也是_(d)目标目录必须包含一?"eclipse
目录。如果找刎ͼ附加的功能部件和插g在运行期配置是将是可用的Q如果链接文件是在工作区创徏之后d的,附加的功能部件和插g?x)作为新的配|变更来?
理?
其它压羃文g解压后若已经包含eclipse"plugins目录Q则不需要徏立eclipse目录?/p>
然后?nbsp;eclipse安装目录D:"eclipse目录中徏立一个子目录linksQ在links目录中徏立一个link文gQ比? LanguagePackFeature.linkQ改文g内容?nbsp; path=D:/plug-in/LanguagePackFeature 卌个link文g要对应一个刚解压后的插g目录?/p>
说明Q?/strong>
1. 插g可以分别安装在多个自定义的目录中?/p>
2. 一个自定义目录可以安装多个插g?/p>
3. link文g的文件名?qing)扩展名可以取Q意名Uͼ比如ddd.txtQmyplugin都可以?/p>
4. link文g中path=插g目录的path路径分隔要用""或是/
5. 在links目录也可以有多个link文gQ每个link文g中的path参数都将生效?/p>
6. 插g目录可以使用相对路径?/p>
7. 可以在links目录中徏立一个子目录Q{UL时不用的插g到此子目录中Q加快eclipse启动?nbsp;
8. 如果安装后看不到插gQ把eclipse 目录下的configuration目录删除Q重启即可?/p>
JUnit is a simple Java testing framework to write tests for you Java application. This tutorial gives you an overview of the features of JUnit and shows a little example how you can write tests for your Java application.
Author:
Sascha Wolski
Sebastian Hennebrueder
http://www.laliluna.de/tutorials.html ? Tutorials for Struts, EJB, xdoclet and eclipse.
Date:
April, 12 2005
Software:
Eclipse 3.x
Junit 2.x
Source code:
http://www.laliluna.de/assets/tutorials/junit-testing-source.zip
PDF Version
http://www.laliluna.de/assets/tutorials/junit-testing-en.pdf
JUnit is a simple open source Java testing framework used to write and run repeatable automated tests. It is an instance of the xUnit architecture for unit testing framework. Eclipse supports creating test cases and running test suites, so it is easy to use for your Java applications.
JUnit features include:
Assertions for testing expected results
Test fixtures for sharing common test data
Test suites for easily organizing and running tests
Graphical and textual test runners
A test case is a class which holds a number of test methods. For example if you want to test some methods of a class Book you create a class BookTest which extends the JUnit TestCase class and place your test methods in there.
Create a subclass of TestCase:
public class BookTest extends TestCase{
//..
}
Write a test method to assert expected results on the object under test:
Note: The naming convention for a test method is testXXX()
public void testCollection() {
Collection collection = new ArrayList();
assertTrue(collection.isEmpty());
}
Write a suite() method that uses reflection to dynamically create a test suite containing all the testXXX() methods:
public static Test suite(){
return new TestSuite(BookTest.class);
}
Activate the JUnit view in Eclipse (Window > Show View > Other.. > Java > JUnit).
You find the JUnit tab near the Package Explorer tab. You can change the position of the tab by drag and drop it.
Right click on the subclass of TestCase and choose Run > JUnit Test to run the test.
A test fixture is useful if you have two or more tests for a common set of objects. Using a test fixture avoids duplicating the test code necessary to initialize and cleanup those common objects for each test.
To create a test fixture, define a setUp() method that initializes common object and a tearDown() method to cleanup those objects. The JUnit framework automatically invokes the setUp() method before a each test is run and the tearDown() method after each test is run.
The following test uses a test fixture:
public class BookTest2 extends TestCase {
private Collection collection;
protected void setUp() {
collection = new ArrayList();
}
protected void tearDown() {
collection.clear();
}
public void testEmptyCollection(){
assertTrue(collection.isEmpty());
}
}
JUnit supports two ways (static and dynamic) of running single tests.
In static way you override the runTest() method inherited form TestCase class and call the desired test case. A convenient way to do this is with an anonymous inner class.
Note: Each test must be given a name, so you can identify it if it fails.
TestCase test = new BookTest("equals test") {
public void runTest() {
testEquals();
}
};
The dynamic way to create a test case to be run uses reflection to implement runTest. It assumes the name of the test is the name of the test case method to invoke. It dynamically finds and invokes the test method. The dynamic way is more compact to write but it is less static type safe. An error in the name of the test case goes unnoticed until you run it and get a NoSuchMethodException. We leave the choice of which to use up to you.
TestCast test = new BookTest("testEquals");
If you have two tests and you'll run them together you could run the tests one at a time yourself, but you would quickly grow tired of that. Instead, JUnit provides an object TestSuite which runs any number of test cases together. The suite method is like a main method that is specialized to run tests.
Create a suite and add each test case you want to execute:
public static void suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
suite.addTest(new BookTest("testBookAdd"));
return suite;
}
Since JUnit 2.0 there is an even simpler way to create a test suite, which holds all testXXX() methods. You only pass the class with the tests to a TestSuite and it extracts the test methods automatically.
Note: If you use this way to create a TestSuite all test methods will be added. If you do not want all test methods in the TestSuite use the normal way to create it.
Example:
public static void suite(){
return new TestSuite(BookTest.class);
}
Create a new Java project named JUnitExample.
Add a package de.laliluna.tutorial.junitexample where you place the example classes and a package test.laliluna.tutorial.junitexample where you place your test classes.
Create a new class Book in the package de.laliluna.tutorial.junitexample.
Add two properties title of type String and price of type double.
Add a constructor to set the two properties.
Provide a getter- and setter-method for each of them.
Add a method trunk for a method equals(Object object) which checks if the object is an instance of the class Book and the values of the object are equal. The method return a boolean value.
Note: Do not write the logic of the equals(..) method, we do it after finish creating the test method.
The following source code shows the class Book.
public class Book {
private String title;
private double price;
/**
* Constructor
*
* @param title
* @param price
*/
public Book(String title,
double price) {
this.title = title;
this.price = price;
}
/**
* Check if an object is an instance of book
* and the values of title and price are equal
* then return true, otherwise return false
*/
public boolean equals(Object object) {
return false;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
Create a new test case BookTest in the package test.laliluna.tutorial.junitexample Right click on the package and choose New > JUnit Test Case.
In the wizard choose the methods stubs setUp(), tearDown() and constructor().
The following source code shows the class BookTest
public class BookTest extends TestCase {
/**
* setUp() method that initializes common objects
*/
protected void setUp() throws Exception {
super.setUp();
}
/**
* tearDown() method that cleanup the common objects
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* Constructor for BookTest.
* @param name
*/
public BookTest(String name) {
super(name);
}
}
Now we want to write a test for the equals(..) method of the class Book. We provide three private properties, book1, book2 and book3 of type Book.
private Book book1;
private Book book2;
private Book book3;
Within the setUp() method we initializes the three properties with some values. Property book1 and book3 are the same.
protected void setUp() throws Exception {
super.setUp();
book1 = new Book("ES", 12.99);
book2 = new Book("The Gate", 11.99);
book3 = new Book("ES", 12.99);
}
Within the tearDown() method we cleanup the properties:
protected void tearDown() throws Exception {
super.tearDown();
book1 = null;
book2 = null;
book3 = null;
}
Now, add a test method testEquals() to the test case. Within the method we use the assertFalse() method of the JUnit framework to test if the return-value of the equals(..) method is false, because book1 and book2 are not the same. If the return-value is false the logic of the equals() method is correct, otherwise there is a logical problem while comparing the objects. We want to test if the method compares the objects correctly by using the assertTrue() method. Book1 and Book3 are the same, because both are an instance of the class Book and have the same values.
The following source code shows the testEquals() method:
public void testEquals(){
assertFalse(book2.equals(book1));
assertTrue(book1.equals(book1));
}
We have finished the test and now we can add the logic to the equals() method stub. Open the class Book and add the logic to the equals() method. First we check if the object given by the method is an instance of Book. Then compare the properties title and price, if they are equal return true.
public boolean equals(Object object) {
if (object instanceof Book) {
Book book = (Book) object;
return getTitle().equals(book.getTitle())
&& getPrice() == book.getPrice();
}
return false;
}
In order to run the test method testEquals() add a method suite() to the class BookTest.
Note: You can also create a separate class where you add the suite() method.
Within the method create a new instance of TestSuite and use the method addTest(..) to add a test. Here we use the dynamically way to add a test to a TestSuite.
The method looks like the follows:
public static Test suite(){
TestSuite suite = new TestSuite();
suite.addTest(new BookTest("testEquals"));
return suite;
}
After finishing all test methods we want to run the JUnit test case. Right mouse button on the class BookTest and choose Run As > JUnit Test.
On the JUnit view (Menu Windows -> show view) of Eclipse you can see how many runs, errors and failures occurred.
This tutorial gives you an overview of how to use the debugging feature of eclipse to debug your web or Java projects.
Author:
Sascha Wolski
Sebastian Hennebrueder
http://www.laliluna.de/tutorial.html ? Tutorials for Struts, JSF, EJB, Hibernate, xdoclet, eclipse and more.
Datum:
January, 25 2005
Development
Tools
Eclipse 3.x
MyEclipse plugin 3.8
(A cheap and quite powerful Extension to Eclipse to develop Web Applications and EJB (J2EE) Applications. I think that there is a test version availalable at MyEclipse.)
PDF Version des Tutorials
http://www.laliluna.de/assets/tutorials/debugging-jsp-java-tutorial-en.pdf
The Eclipse Platform features a Java debugger that provides all standard debugging functionality, including the ability to perform step execution, setting of breakpoints and values, inspecting variables and values, and to suspend and resume threads. With the extension MyEclipse you are able to debug JSP and included files too.
First we will explain the debug perspective. You can activate the perspective under Windows > Open Perspective > Other...
Alternatively, you can click on the debug icon of the perspective tool bar.
The Debug view displays the stack trace for the suspended threads for each target you are debugging. Each entry is the variable state of a method right when it called the next method. The view allows you to manage the debugging of a program in the workbench.
The view displays information about the variables in the selected class. You can get information about the variable like value, size and more from this view.
The view lists all breakpoints you have set in the workbench project. In this view, you can enable or disable breakpoints, remove them, or add a new ones. You can also double-click a breakpoint to display its location in the editor.
This view also lists Java exception breakpoints, which suspend execution at the point where the exception is thrown. You can add or remove exceptions.
You can inspect data from each class of a suspended thread, and other places in this view. It opens automatically when an item is added to the view.
In the next steps I will explain how you can debug a project. I will refer to the project JSP + Servlet you can download on our site. http://www.laliluna.de/assets/tutorials/java-servlets-jsp-tutorial.zip
Open the class BookEdit.java and set a breakpoint in the method doGet(..) at line 72. You can set a breakpoint by double-click on the info bar on the left edge of the editor, or right click Toggle Breakpoint.
Set the second breakpoint in the bookEdit.jsp file on the HTML start tag at line 14.
Note: If you don't have installed MyEclipse, you can't set a breakpoint in jsp and included files.
To see all breakpoints you can use the Breakpoints view in the debug perspective.
You can apply some properties to each breakpoint, for example how many times a breakpoint can hit before it suspends the thread or on which condition it suspends the thread.
Select the breakpoint right mouse button and choose the option Breakpoint Properties.
The hit count sets a number of times the breakpoint can be executed before the thread suspends. Very helpful in a loop expression or if you want to know the value of a expression after some hits.
There are two options to suspend a thread by using a condition.
if the enabled condition is true
if the enabled condition changes
If you want that the condition suspends the thread when it is true select the option condition is true on Suspend when.
Example:
action.equals("edit");
If you want that the condition suspends the thread when the value of the condition changes select the option value of the condition changes on Suspend when.
You can define if the breakpoint suspends only the thread or the complete virtual machine.
Now we want to debug the project, so deploy
it and call it in your web browser.
Choose Edit on the
list of books.
After you clicked the Edit link, eclipse shows you the following confirm window. You can choose if you want to switch to the debug perspective. Yes, you want it ;- )
The first entry in the debug view represents the state of the method where the breakpoint was set. You can preview the state of a entry simply by clicking on it, also the file will be open where the method is placed.
You can see the values of all variables of the selected entry in the Variables view.
A marked line and an arrow at the breakpoint shows that the debugger is suspended on this line.
If you've decided that you missed an
important place in the execution process, perhaps the breakpoint was
in the wrong place, or maybe you accidentally stepped over some code
you wanted to inspect earlier in the process. Eclipse has a feature
called Drop to frame, that
essentially lets you 'rewind' the execution to the beginning of any
method in the stack. This is especially useful when you perform
variable modification or code hot swapping.
Right click on the
frame and choose the option Drop to Frame.
To get informations about expression, you can inspect a expression. Right click on the marked expression, you want to inspect and choose Inspect or press Ctrl + Shift + I. A pop-up window appears that holds the informations about the expression.
Watch is similar to inspect an expression. Watch means that the expression will be added to the Expressions view, where you can watch the informations about the expression. Add two expressions to the Expressions view.
Mark the expressions, right click and choose Watch.
Now the two expression are in the Expressions view.
If you want to display the type and the value of an expression, mark the expression and choose the Display option from the context menu (right mouse button) or press Ctrl + Shift + D.
If you set a breakpoint and somewhere under the breakpoint is a line you want to go, you can use the option Run to Line. The code between the breakpoint and the selected line will be executed. Select the line you want to go, press the right mouse button and choose the option Run to Line or use the key binding Ctrl + R.
Debugging
a JSP file is the same like debugging a Java class, but the most
features (Watch, Inspect, etc) are not implemented. The only way to
get the values of variables is the Variables view.
That's it. You will only need to debug, when you make mistakes. Avoid them and forget the tutorial.