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 the method that Java uses Junit4.jar for unit testing

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Today, I will talk to you about what Java uses Junit4.jar for unit testing. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

Download the dependency package

Download junit.jar and hamcrest-core.jar respectively

Add to dependency

Create a lib folder in the project and directory, and drag the downloaded dependent packages into it

Move the mouse over the dependency package and right-click to select Add as Library.... Add junit.jar and hamcrest-core.jar to library in turn

Set up the test directory

Create a test folder in the project root directory, and right-click to set Mark Directory as-- Test Sources Root

Create a test class

Write a random class for demonstration

HaHa.java

Public class HaHa {public void sayHaHa () {System.out.println ("HaHa");} public String sayBye () {System.out.println ("Bye"); return "Byt";}}

Ctrl + Shift + T quickly create Test code. Select Create New Test... And choose the method you need to test.

5. Start testing

HaHaTest.java

Import org.junit.Assert;import org.junit.Test;import static org.junit.Assert.*;public class HaHaTest {@ Test public void sayHaHa () {new HaHa () .sayHaHa ();} @ Test public void sayBye () {String bye = new HaHa () .sayBye (); Assert.assertEquals ("Byt", bye);}}

After reading the above, do you have any further understanding of Java's method of unit testing using Junit4.jar? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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

Development

Wechat

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

12
Report