JUnit Unit Test

Source: Internet
Author: User

Demo.java

Package JUnit;/** * Java Build Path--add Library Junit 4 * @author kj **/ Public classDemo { Public intAddintAintb) {        Try{Thread.Sleep ( -); } Catch(interruptedexception e) {//TODO auto-generated Catch blockE.printstacktrace (); }        returnA +b; }         Public intDevide (intAintb) {        returnA/b; }}

Demotest.java

Package Test;import JUnit. Demo;import Org.junit.assert;import org.junit.Test;/** * Method of test: * 1. Methods must be common; * 2. The method return value must be void * 3. The method must be non-parametric * 4. Must be annotated with @test * 5. @before: Methods that must be called once before each test method executes * @beforeclass: is a method static that must be and can only be called once before all test methods are executed. * @after * @afterclass: * 6. * @author KJ **/ Public classdemotest {@Test (timeout= -)//Maximum execution time is 100ms long type is generally MS Unit     Public voidTestadd () {Demo D=NewDemo (); Assert.assertequals (Ten, D.add (4,6)); } @Test (Expected=java.lang.arithmeticexception.class)//A mathematical anomaly occurred     Public voidtestdevide () {Demo D=NewDemo (); Assert.assertequals (2, D.devide (Ten,0)); }}

JUnit Unit Test

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.