Unit 4 uses annotations in Java 5 (annotation), the following is a few annotation introduced by JUnit 4@Before: Initialization method@After: Freeing Resources@Test: Test method, where you can test for expected exceptions and time-outs@Ignore: Ignored
shown in:
Double-click the Java file to enter the code editing state as shown in:
After debugging is complete, the system code has no error prompts, as shown in:
Select Foxgis.java Run as->junit test as shown in:
After execution, you can view the results of the run as shown in:
Select Foxgis.ja
JUnit is a good set of unit testing frameworks, and Maven is a great Java Project Building and management tool that makes it easy to test your project automatically.
In general, simple Java applications don't say much, and some frameworks provide extensions to junit that make testing easier, such as spring's official spring-t
, will produce dirty data, affecting the correctness of our data
Inconvenient cyclic testing, that is, if we delete a record this time, next time we can no longer carry out the JUnit test, because the record has been deleted, will be error.
If we do not use transaction rollback, we need to explicitly restore our additions and deletions to the database ope
JUnit Common annotations:
@Before: Initialization method
@After: Freeing Resources
@Test: Test method, where you can test for expected exceptions and time-outs
@Ignore: Ignored test methods
@BeforeClass: For all t
[This article is from the Sky Cloud-owned blog Park]Brief descriptionUsing JUnit combined with Mockito, coupled with some of the Spingframework's own methods, can be combined to test the controller layer in spring MVC.Before we design the test case, we have to take the logic of the controller's code in-depth and go through the drill-by-layer. The purpose of the w
using ant to integrate JUnit for Automatic Testing and generate test reports can greatly improve the test efficiency. The advantage is the batch processing function of test cases. Not long ago, I saw a lot of articles about JUnit testing on the Internet: . I'm glad ant has
Using the spring framework to make it easy to write code with separate tests for some code snippet code without having to run the entire environment for testing, the JUnit test is introduced to facilitate the testing of the local code block.1, first guide package, such as MAVEN project: where JUnit needs at least in the 4.12 version, or will be
Test exception occurs when unit tests are in progressin thread "main" java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.getDefaultClassLoader()Ljava/lang/ClassLoader;The error is in pom.xml the dependency, look carefully at the console output and you will find that IntelliJ idea is trying to run my test case using JUNIT5.com.intellij.ju
as long to be an error when executing the constructor $object[][] data =Newobject[][]{{1,2},{2,3},{4,5}}; - returnArrays.aslist (data);//Convert an array into a collection - } the - Wuyi @Test the Public voidTestadd () { - DoubleResult_add =Calculate.add (INPUT1, input2); WuSystem.out.println ("Addesult:" +result_add); - //asserts that if it is not the same as expe
, will produce dirty data, affecting the correctness of our data is not convenient cycle test, that is, if we delete a record, the next time we can not do this junit test, because the record has been deleted, will be an error. If you do not use transaction rollback, we need to explicitly restore our additions and delet
Since only one junit test has been written, and the test project logic is complex, the following are just a few of the solutions to the problems encountered in the test.Web server: LinuxClient: Linux/windows (as long as you can execute Java program, test Java-jar Test_client.jar)Problem1, because the
method (public void) has attributes expected and timeout
Expected: Specifies the exception class, and the test succeeds if an exception is thrown
@Test (expected=exception. Class)
Public void Testcaculatedbyzero () throws exception{
Cal.divide (10, 0);
}
Timeout: The test fails if the test time exceeds the Timeout sp
, will produce dirty data, affecting the correctness of our data
Inconvenient cyclic testing, that is, if we delete a record this time, next time we can no longer carry out the JUnit test, because the record has been deleted, will be error.
If we do not use transaction rollback, we need to explicitly restore our additions and deletions to the database ope
Android junit unit test, androidjunit
Classification of software testing* Black box testing* Test the logical business* White box testing* Test logic method
Based on test Granularity* Method test: function
The course design requires the JUnit test, which I tested on the already well-done SSH project, and the test class code is as followsPackage Com.zhang.web.services;importStaticorg.junit.assert.*; import org.junit.after;import org.junit.before;import org.junit.test;import javax.annotation.Resource; Import Org.junit.runner.RunWith; Import Org.springframework.test.
Accuracy test (result accuracy testing)For example, Assert.assertequals (expected, actual).If the result does not meet the expectations, it produces failure. Indicates a problem with the program logic.Failure test (throwing exception tests)The expected property is used to indicate the type of exception expected to be thrown. For example, @Test (expected = illegal
The Hibernate entity classes and their mapping files are also placed in the project, and because there are multiple projects using the same database, Hibernate entity classes and mapping files are duplicated, which is inconvenient for maintenance and upgrades. Therefore, it is extracted, made into a jar package, and then introduced back to the project.
In practice, there is a strange problem: The project runs fine, but the JUnit unit
Classification of software Testing* Black box test* Test Logic Business* White Box test* Test Logic methodAccording to the test grain size* Method Test: Function test* Unit tested: Unit
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.