Java Tour hibernate (6)--junit Untold Stories

Source: Internet
Author: User
Tags assert

Speaking of JUnit, we first have to say the importance of testing. A robust software is sure to be applied after a constant test of ability. In the test process can find a lot of instability or there is a certain number of bugs and so on. These can be found in the test phase. Without being pushed to the point where the user is actually using it. Avoid a less-than-good user experience.

When we look at the Java source program. Always see this kind of a directory, the name of test, curious whether you have opened it?

Yes, this is the test program that we write, which makes it in the team development process. Each other's interactions are more reliable and stable.

So what is junti in detail?

1. Junit 

If you want to use it in JUnit. You must first introduce the JUnit package and download a JUnit package on the web with the suffix named jar. Open Eclipse and create a new project. After the project is built, right-click on the project name and choose Build Path-->config build Path, in properties for .... On the left side of the form, select Java Build Path to the right of libraries, and then click Add External Jars. Find the JUnit package that you downloaded. Click Open, and then click OK. You're ready.

? Set up a test directory, the directory is "Source Folder" type  

? Create a new class to test "Usermanager"  

? Create a test program (JUnit is a control using the expected and actual values)  

? Results  

This is a rough example of how we collect information online in detail.

2. Not known--combination mode 

A while ago, we launched a design mode speech contest, very honored that I was selected as the leader. Our group is responsible for the combined pattern. After seeing this pattern, I first contacted life and looked at some examples of life.

Combination Mode diagram:

? Combined Mode Life Chapter  

Each of our families have a family tree, then the family tree is a combination of patterns, how to say?

Compare the above combination pattern diagram: The top is father, father and mother after married have a daughter and son. and daughters are incapable of procreation. But the son can. The son of the following is able to divide, the whole group into a family.

In addition, like the trees outside the window, there are trunk and branches and leaves and so on, as well as our operating system files and directories, and so on, these are common in our lives, here no longer say.

? The combination mode wonderful article  

Inadvertently see some of the data, found that we often use the unit test "Junit" is actually a model. As Columbus discovered the New World, my heart was filled with joy.

Let us now uncover this magical veil in a layer.

When we write test procedures, we often write these words:

public class Test extends TestCase {

}

In fact, TestCase is not a separate existence. It actually implements a certain interface, this interface is test, besides TestCase, our other test class is testsuite. It actually contains a collection of testcase. So the relationship between the three is out. Let's have a look.

TestCase   

Definition: Abstract class TestCase extends assert implements Test inherits the Assert class and implements the Test interface. And it's an abstract class.

   TestSuite

Definition: Class TestSuite implements Test; The implementation class of the Test interface is the same as testcase. But Testsuite is a collection of testcase that will all be executed testcase add to Testsuite.

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

Assuming that the previous one is a single test, and the back one is a combination of tests, the combined test can not only add a test class to a number of test methods. And can join multiple test classes. So, is this a special combination of patterns?

Take a look at the combo pattern above and draw our graph is

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">

When we learn to combine patterns. In fact, JUnit is very similar to the graph of the tree node, and the testcase is equivalent to the leaf node, and the following cannot be added again. and Testsuite not the same, it is a branch of the node, it is able to join again, and we have learned the "Big talk design mode" on the same, testsuite not only can join TestCase, but also can join Testsuite. Because it adds an object, it is actually the equivalent of adding a test.

3. Summary 

This is a primer I throw. As for the use or need everyone to practice, interested can go to see ~

Java Tour hibernate (6)--junit Untold Stories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.