not equal. Similar to using "! =" to compare two objects
asserttrue (condition)
to see if the run result is true.
assertfalse (condition)
to see if the run result is false.
assertthat (Actual, matcher)
See if the actual value meets the specified condition
fail ()
let test fail
See if two arrays are equal.
Annotations
Spring Boot Junit unit test
The old Junit technology is nothing more than to mention, to some extent, to illustrate its importance in the project.Based on my own feelings and experience, the Junit Use Cases Written completely in the project to cover most of the Business Code should not exceed half.
I wrote some posts a
(version control) + ANT (Project management) + JUnit (integration testing) mode, can be easily implemented by using ant's configuration for automated testing.For subjects of different properties, such as CLASS,JSP,SERVLET,EJB, JUnit has different techniques for using, and then slowly Apple told. The following is an example of a class
Java Unit Test Framework JUnitJUnit is a unit test framework for the Java language. It was founded by Kent Beck and Erich Gamma, and gradually became the most successful of the Xunit family of Sunit from Kentbeck. JUnit has its own JUnit expansion biosphere. Most Java development environments have integrated
corresponding four methods and click Finish. A test class is automatically generated, but we still need to modify the class to the following code.
1 package Org. logback. test; 2 3 Import static Org. JUnit. assert. *; 4 5 import Org. JUnit. after; 6 Import Org.
framework
First, we provide an example of using the new extension for parallel testing.
Example 1. Use JUnit extension for parallel testing
/** * @author Zhi Gan * */ @RunWith(Parallelized.class) @ParallelSetting(threadNumber = { 1, 2, 4, 8 }) public class TestThreaded { Set @Before public void setUp
, no Junit3 constraints, which are convenient to use and for the Calc test are as follows:3. For unit tests in Java, the type of method being tested is generally or can be converted to the following four types:A. The method under test has a return value, and the return value is predictable. (According to the function, the specific input must correspond to the specific output); Assertequals (expected value,
static-defined classes, you can easily debug with your favorite debugging program. (The example used in this article assumes that Eclipse IDE is used. However, the technology I described here can be used in most other ides without many modifications .) When making any design decision, you must weigh the impact of the selection and decision. Here, in order to obtain the ability to debug dynamically generated test
int Add (int a, int b)
{
return a + b;
}
public int subtract (int a, int b)
{return a-a
;
}
public int multiply (int a, int b)
{
return a * b;
}
public int divide (int a, int b)
{
return a/b;
}
}
2. Add the JUnit library
Then in order to use JUnit, you need to join the library:
Right-click on the project properties-
versions of common Android objects.4. A tool that runs a single test or test suite with or without Instrumentation.5. You can use the Eclipse ADT plug-in and command line to manage the Test and Test projects.
Ii. JUnit core fram
Java (5) --- talking about JUnit 4
Junit4
JUnit4 fully introduces Annotation to execute the tests we have written.
1. JUnit 4 does not require the test class to inherit the TestCase parent class.
2. In a Test class, all publ
1. Learn the use of the JUnit frameworkYou can learn from the following two examples.A, JUnit use Method Example 11) bring JUnit into the current project libraryCreate a new Java Project-cooljunit, open the Project Cooljunit's property page, select the Java Build Path Sub-option, click the "Add Library ..." button, an
JUnit is a regression testing framework (regression testing framework) written by Erich Gamma and Kent Beck for Java developers to write unit tests. JUnit has different techniques for using objects of different natures, such as CLASS,JSP,SERVLET,EJB. The following is an example of a class test.Test steps:1 Importing JUNIT4-related jar packages(Select Java Project
,JUNIT4 than 3 to facilitate a lot, the details can be understood, the main is version 4 of the method naming format no longer have requirements, no longer need to inherit testcase, everything is based on annotations implementation.1 Springboot How to use JUnit in Web projectsCreate a plain Java class that no longer needs to inherit the TestCase class in JUNIT4.Because we are Web projects, we add annotation
This article describes how to properly test exceptions under JUnit 4, and I'll start with the try. Catch the way to talk about, and then to @Test (Expected=exception.class), and finally on the @Rules public expectedexception implementation, the final basic can be determined with @Rules is the most convenient. When we u
void Add () {System.out.println ("add");int x = 0;int y = 0;addoperation instance = new Addoperation ();int expresult = 0;int result = Instance.add (x, y);Assertequals (Expresult, result);}}We can see that the adoption of annotation JUnit has not been overbearing enough to require you to inherit from the TestCase, and the test method does not have to start with test
JUnit 4 uses the annotation (annotation) in Java 5. The following describes several annotation commonly used in JUnit 4.@ Before: Initialization Method@ After: release resources@ Test: Test method. The expected exception and timeo
junit3 and the JUNIT4 the use of the difference is as follows1. the TestCase class needs to be inherited in JUnit3, but no inheritance is required in JUNIT4 testcase2. in JUnit3, you need to overwrite the setup and Teardown methods in the TestCase, where the Setup method is called to complete initialization before the test executes, and the Teardown method is invoked when the test results are closed. Used t
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.