Introduction and application of junit test

table of Contents

1.junit test Introduction

2. Operating Environment

3. Test procedure

 

 

 

1.junit test Introduction

JUnit is a unit testing framework for the Java language. It was founded by Kent Beck and Erich Gamma, has gradually become due sUnit Kent Beck's xUnit family of one of the most successful. JUnit JUnit extension has its own ecosystem. Most Java development environment have been integrated as a tool for JUnit unit testing.

JUnit is written by Erich Gamma and Kent Beck a regression testing framework (regression testing framework). Junit test is a programmer tests, the so-called white-box testing , because of how the software being tested (How) completion and what (What) function to complete the programmers know. Junit is a framework, inheritance TestCase class, can be automatically tested with Junit.
  In simple terms, a test similar to the debug junit c language, only the commissioning test is performed by setting breakpoints partition codes; and the java junit is tested separately by different classes and methods implemented (because java is object-oriented, he can not be breakpoint debugging process-oriented language like C in common sense, and does not facilitate).
 
2. Operating Environment
  junit can be achieved by ide quick test, I used here is the eclipse, where the need to test the class to add new-other-java-junit can be tested. Here is junit4 commissioning, the latest version of junit junit5 on the difference between the two versions, the most significant difference is the difference in supported versions:. Java4 support java5 and above versions, and more than java5 only support java8 version of. In addition, in some of the comments and details differ. To learn more about can view this blog, which has a detailed description here is not launched: https://blog.csdn.net/u010675669/article/details/86574956 https://blog.csdn.net/u010675669 / Article This article was / the Details / 86,574,956 .
 
 
3. Test procedure
  Class is defined herein as tested (in the first package):
package first;

class junit {
    public int add(int a, int b) {
        return a + b;
    }

    public int sub(int a, int b) {
        return a - b;
    }

    public  int mult ( int a, int b) {
         return a * b;
    }

    public int div(int a, int b) {
        return a / b;
    }
}

We want some of them to test operation. There are a quick way to generate the eclipse test code. Here the test code shown below:

package first;

import static org.junit.Assert.*;

import org.junit.Test;

import first.junit;

public  class junitTest {

    @Test
    public  void testAdd () {
        assertEquals(5,new junit().add(2,3));
    }

    @Test
    public  void test mult () {
        assertEquals(5,new junit().mult(2,3));
    }

    @Test
    public void testDiv() {
        assertEquals(8,new junit().div(4, 2));
    }

}

Guess you like

Origin www.cnblogs.com/upuphe/p/12364633.html