Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method that Java uses Junit4.jar for unit testing

Shulou Source: shulou.com Published: 2022-06-02 16:55:38 10月15日 Update

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.

Tags: Test method content selection unit file folder directory project code more root directory knowledge article industry information information channel channel mouse enter one Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Redmi Shulou Information Shulou Tech Info