Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is JUnit?

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what is JUnit". In daily operation, I believe many people have doubts about what JUnit is. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is JUnit?" Next, please follow the editor to study!

JUnit is an open source testing framework for writing and running repeatable automated tests

Maven pom.xml configuration

Junit junit 4.12 test

Create a HelloTest test class in / src/test/java/HelloTest.java

Public class HelloTest {@ Before public void before () {System.out.println ("before func");} @ After public void after () {System.out.println ("after func");} @ Test public void testFoo () {System.out.println ("test foo");}}

# JUnit comments

The annotation description @ Test test comment indicates that the public invalid method it is attached can be used as a test case. The @ Before comment indicates that the method must be executed before each test in the class in order to perform some of the necessary prerequisites for the test. The @ BeforeClass comment indicates that this is attached to the static method that must be executed once and before all tests of the class. When this happens, you typically test the calculation shared configuration method (such as connecting to a database). @ After this method is executed after each test (such as resetting some variables after each test, deleting temporary variables, etc.) @ AfterClass when all tests need to be executed after the JUnit test case class, the AfterClass annotation can be used to clean up the build method (such as disconnecting from the database). Note: methods with this annotation (similar to BeforeClass) must be defined as static. @ Ignore can use ignore comments when you want to temporarily disable specific test execution. Each method annotated as @ Ignore will not be executed. At this point, the study of "what is JUnit" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report