"Java from getting started to giving up" javase introductory article: unit testing

Source: Internet
Author: User
Tags ming

Unit testing In fact there is nothing to say, look directly at the operation step!

Let's test the previous article about how Xiao Ming buys food.


First step: Right-click on the Xiao Ming class and then new one junit Test case

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/A5/8D/wKioL1m_iAygNbgSAABZDwejGG4076.png "title=" 11. PNG "width=" "height=" 381 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:381px; "alt=" wkiol1m_ Iaygnbgsaabzdwejgg4076.png "/>


The second step: continue to point next, the contents of the picture believe that we can understand it, if you do not understand, it will either study, or give up, haha!

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/A5/8D/wKioL1m_iEySlcn5AACcOOt9Zrk966.png "title=" 12. PNG "width=" "height=" 482 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:482px; "alt=" wkiol1m_ Ieyslcn5aaccoot9zrk966.png "/>


Step three: Tick the method you want to test:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/A5/8D/wKioL1m_iJrxZnF0AACo6a2FE9c561.png "title=" 13. PNG "width=" "height=" 482 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:482px; "alt=" wkiol1m_ Ijrxznf0aaco6a2fe9c561.png "/>


Fourth step: Click OK to import the jar packages you need to use with JUnit

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/A5/8D/wKioL1m_iMiyAQZkAABI4PuIcbU206.png "title=" 14. PNG "width=" "height=" 226 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:400px;height:226px; "alt=" wkiol1m_ Imiyaqzkaabi4puicbu206.png "/>


Fifth step: Automatically generated a xxxtest class, which contains a testxxx method, which has a @test annotation, because we do not check the initialization method, so all the code is written directly in the Testxxx method.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/A5/8D/wKioL1m_iPiAynKtAACL1stV3TQ996.png "title=" 15. PNG "width=" "height=" 246 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:600px;height:246px; "alt=" wkiol1m_ Ipiaynktaacl1stv3tq996.png "/>


Sixth step: Write the assertion, enter the test data, and then determine whether the return result of the method is our predicted value, if so, the method tested is not a problem under the current data. In practice, each case will be tested in a few sets of boundary data to determine whether the method has a bug, the test results have two cases, if the green means that the test results and the same prediction results, the method is not a problem , otherwise the method has a bug.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/A5/8D/wKioL1m_i2nStjUfAACVa4GX_LA792.png "style=" width : 900px;height:272px; "title=" 16.png "width=" "height=" 272 "border=" 0 "hspace=" 0 "vspace=" 0 "alt=" wkiol1m_ I2nstjufaacva4gx_la792.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/06/DD/wKiom1m_i5qRJzskAACtO74T_PU215.png "title=" 17. PNG "width=" "height=" 294 "border=" 0 "hspace=" 0 "vspace=" 0 "style=" width:900px;height:294px; "alt=" wkiom1m_ I5qrjzskaacto74t_pu215.png "/>



Unit testing is so simple!!! 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0019.gif "alt=" J_0019.gif "/>


"Software Thinking" blog address: 51CTO , Blog Park , interested small partners can go to see the relevant other blog posts.


This article is from the "Software Thinking" blog, please be sure to keep this source http://softi.blog.51cto.com/13093971/1966413

"Java from getting started to giving up" javase introductory article: unit testing

Related Article

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.