当前位置:网站首页>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);
}
}
边栏推荐
- asp. Net web page, ASP connects to the database, and uses asp:panel and asp:dropdownlist controls
- 【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
- WPF value conversion
- Li Kou 79 word search
- Analysis of the principle of obxwidget
- Lua语法讲解
- EF core Basics
- 面了个字节拿25k出来的测试,算是真正见识到了基础的天花板
- 商城风格也可以很多变,DIY 了解一下
- 阿里云函数计算服务一键搭建Z-Blog个人博客
猜你喜欢

Yolov5 improvements: replace the backbone

軟件調試測試的十大重要基本准則

Unity mobile game performance optimization spectrum CPU time-consuming optimization divided by engine modules

ABP framework

YOLOv5改进:更换骨干网(Backbone)

第 4 篇:绘制四边形

Tencent Interviewer: How did binder get its system services?

Quanergy欢迎Lori Sundberg出任首席人力资源官

chrome页面录制,重放功能

Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
随机推荐
Camera memory memory leak analysis (III)
(15) Blender source code analysis flash window display menu function
三元损失英文版
Prism framework project application - Navigation
English version of ternary loss
[从零开始学习FPGA编程-45]:视野篇 - 集成电路助力数字化时代高质量发展-2-市场预测
asp. Net web page, ASP connects to the database, and uses asp:panel and asp:dropdownlist controls
After four years of outsourcing, people are directly abandoned...
【Flink】Flink 批处理模式Map端数据聚合 NormalizedKeySorter
Detr3d multi 2D picture 3D detection framework
What if the serial port fails to open when the SCM uses stc-isp to download software?
阿里云函数计算服务一键搭建Z-Blog个人博客
Read / write lock for thread synchronization
Spark - understand parquet
力扣79单词搜索
Machine learning notes - trend components of time series
What should I do if the 51 SCM board cannot find the device in keil
解析JSON接口并批量插入到数据库中
WPF 值转换
Judge the same value of two sets 𞓜 different values