当前位置:网站首页>Daily tests
Daily tests
2022-06-26 04:05:00 【Code Xiaoyou】
Classification of tests
1. White box testing
Need to write code , Focus on the specific implementation process of the program
2. Black box testing
Don't write code , Enter value for , See if the program can output the expected value
White box testing :
Junit Use
1. Define a test class ( The test case )
Suggest :
Test class name : The name of the class being tested Test
Package name :xxx.xxx.xx.test
2. Define test methods : Can run independently
Suggest :
Method name :test Test method name
Return value :void
List of parameters : Empty ginseng
3. Add to the method @Test
4. Import junit Depend on the environment
The verdict :
Red : Failure
green : success
Generally, we will use the punctuation operation to process the results
Assert.assertEquals( Expected results , Result of operation )
@Before:
Modified methods are automatically executed before testing methods
@After:
The modified method is automatically executed after the test method
1. Defined Calculator class
package cn.itcast.junit;
/**
* Calculator class
*/
public class Calculator {
/**
* Add
* @param a
* @param b
* @return
*/
public int add(int a,int b){
return a+b;
}
/**
* Subtraction
* @param a
* @param b
* @return
*/
public int sub(int a,int b){
return a-b;
}
}
2. Defined test class
package test;
import cn.itcast.junit.Calculator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
/**
* The test method
*/
public class Calculatortest {
/**
* Initialization method
* Application for resources , All test methods are executed before execution
*/
@Before
public void init(){
}
/**
* Resource release method
* After all test methods are executed , The method is automatically executed
*/
@After
public void close(){
}
@Test
public void testadd(){
Calculator c =new Calculator();
int result =c.add(1,2);
System.out.println(result);
// Punctuation Set a result value and compare it with the result value of the program
Assert.assertEquals(3,result);
}
@Test
public void testsub(){
Calculator c =new Calculator();
int result =c.sub(1,2);
System.out.println(result);
Assert.assertEquals(3,result);
}
}
边栏推荐
- Camera memory memory leak analysis (III)
- [collection of good books] from technology to products
- Matplotlib multi line chart, dot scatter chart
- asp.net网页选择身份进行登录的简单代码,asp连接数据库,使用asp:Panel、asp:DropDownList控件
- Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
- MapReduce execution principle record
- 用eclipse连mysql数据库出错然后出现图中的话是咋回事呀
- 2021 year end summary
- Open camera anomaly analysis (I)
- Spark - 一文搞懂 parquet
猜你喜欢

Chrome page recording and playback function

商城风格也可以很多变,DIY 了解一下

Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions

用eclipse连mysql数据库出错然后出现图中的话是咋回事呀

What should I do if the 51 SCM board cannot find the device in keil

力扣 515. 在每个树行中找最大值

Yolov5 improvements: replace the backbone

User control custom DependencyProperty

ABP framework Practice Series (II) - Introduction to domain layer

Verrouillage de lecture et d'écriture pour la synchronisation des fils
随机推荐
Webrtc series - 7-ice supplement of network transmission preference and priority
EF core Basics
Binary search method
Oracle技术分享 oracle 19.14升级19.15
Introduction of mybatis invalid
matplotlib多条折线图,点散图
Which is the best embedded visual programming software? (introduction, evaluation and selection of visual programming platform) [scratch, mind+, mixly]
Quanergy welcomes Lori sundberg as chief human resources officer
asp. Net web page, ASP connects to the database, and uses asp:panel and asp:dropdownlist controls
[MySQL] MySQL export database
Introduction Guide to the flutterplugin plug-in in the actual combat of flutter
第 4 篇:绘制四边形
ABP framework Practice Series (I) - Introduction to persistence layer
线程同步之读写锁
Capture packets (Wireshark)
MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
Yolov5 improvements: replace the backbone
Oracle technology sharing Oracle 19.14 upgrade 19.15
Getting started with flask
判断两个集合的相同值 ||不同值