Test practice: junit (2) reproduced by Eclipse

xiaoxiao2021-03-06  58

Test Practice: Junit of Eclipse (2)

(Using Junit with eclipse IDE)

(carry on)

Establish our simple Test Case by following two steps;

1. Establish an instance of junit.framework.testcase.

2. Define some test functions starting with "TEST" and return an empty value. (Such as TestWastranscationsUccessful (), testshow (), etc.).

TestttWegetHelloWorldPrompt.java simultaneously follows these standards: These TestCase subclasses contain a TestSay () method. This method is called by the assertequals () method for verifying the return value of SAY () (according to the way it is returned, because At the beginning, the HelloWorld we let Say () return to NULL).

The main () pig function is used to run TEST and display the result of the output. JUnit's Testrunnery performs our TEST and feedback information in the way (Swing.u) graphics and this article (Text.ui |). We use text (Text.ui), this Eclipse is affirmed. (Translation: There may be no translation here, the so-called text and graphic, refers to the time when establishing Testcase, there is a option, which method stubs would you like To create, choose Text.ui || Swing.ui || AWT.UI, usually selection text.ui because Eclipse is definitely supported, in accordance with these text information, Eclipse simultaneously generates graphic display. (I will see multiple junit on the Tab of Package Exploer, and I will see it :).

So, according to the development of the drive-driven development, once we ran our test, we should see the information returned to some errors. Point Run-> Run As -> JUnit Test (note, this test.java should be in Package Explorer, in the left of the Window), you point to the JUnit Window (that is the TAB bar below, Note that it is not Package Exploer, so you will see JUnit Window, he will display a red strip, failing Test. If you press Run it without automatic transfer to this window, you can click on the JUnit label on the TAB bar.

It's too good to run, and it's wrong. Ok, now officially start building the HelloWorld code used to work, --- Point New-> Class, possibly with the original repetition, then delete it. code show as below:

Hellowolrd.java

Public class helloworld {

Public string say () {

Return ("Hello World!");

}

}

This is a simple, you don't need a comment. Test now to see the results. Just use the above method, click Run-> Run as jnit. A green strip appears in the JUnit window on the left. See Figure 3. The green strip indicates the test.

Now, we need to let him fail again, but change this reason. This will help us understand how the JUnit Test covers and reports different errors. Edit the assertequals () method, turn its return value from "Hello World!" To another value such as "Hello Me!". This way, when you run this JUnit Test, the display strip becomes red, and See what is seen in Failuer TRACE leads to errors. to sum up. I want to say some of my own ideas (here is still the original text is not translated). I didn't think that the test code was a very important part of the development process. However, in recent years, it has developed very quickly, thanks to those methodology (such as exception development "Exceptions-Based Development", they have promoted testing and testing tools.

If you are interested in this article, you can spend some time to learn the test theory and apply it to your work. .

The author introduces Alexander Prohorenko Advanced UNIX System Administrator, network security administrator.

OLEXIY PROHORENKO JAVA developers he lived in Ukraine, Roves (found in the football team :)

(Full text is finally translated)

Learn to test some resources:

JUINT Home: http://www.junit.org/index.htm

Support Struts Framework's JUnit component: http://strutstestcase.sourceforge.net/

About XP and website http://www.chianxp.org

"Refactoring" Chinese "Refactoring" Hou Jie translated.

.

In short, I think this is a very simple entry article, it is easy to understand, so it is translated by the face.

Here I expressed apology to the authors of the original text, and my English teacher, I gave you old.

If there is a place where you have a child, please correct it in time, and I hope to test the expert with my rookie.

E-mail zhangli@telecomjs.com

2004-2-11

转载请注明原文地址:https://www.9cbs.com/read-118099.html

New Post(0)