当前位置:网站首页>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)
- 【掘金运营套路揭露】真心被掘金的套路....
- The stc-isp burning program for 51 single chip microcomputer always shows that "the target single chip microcomputer is being detected..." the cold start board does not respond
- 而是互联网开始有了新的进化,开始以一种全新的状态出现
- What if the serial port fails to open when the SCM uses stc-isp to download software?
- MySQL common statements
- Tencent Interviewer: How did binder get its system services?
- I/o virtualization technology - vfio
- Restful API interface design standards and specifications
- MySQL est livré avec l'outil de test de performance MySQL lap pour effectuer des tests de résistance
猜你喜欢

Camera memory memory leak analysis (III)

win10 系统打开的软件太小,如何变大(亲测有效)

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

chrome页面录制,重放功能

ABP framework

ABP framework Practice Series (I) - Introduction to persistence layer

Read / write lock for thread synchronization

Verrouillage de lecture et d'écriture pour la synchronisation des fils

阿里云函数计算服务一键搭建Z-Blog个人博客

Threejs专用天空盒素材,五种天空盒素材免费下载
随机推荐
The style of the mall can also change a lot. DIY can learn about it
How do wechat applets delay? Timing? Execute a piece of code after? (kengji)
Prism framework project application - Navigation
[LOJ 6718] nine suns' weakened version (cyclic convolution, arbitrary modulus NTT)
2021 year end summary
面了个字节拿25k出来的测试,算是真正见识到了基础的天花板
Camera-CreateCaptureSession
Optimization - multi objective planning
ABP framework Practice Series (III) - domain layer in depth
XML parsing bean tool class
Sorting out the examination sites of the 13th Blue Bridge Cup single chip microcomputer objective questions
钉钉开放平台-小程序开发实战(钉钉小程序服务器端)
After four years of outsourcing, people are directly abandoned...
go time包:秒、毫秒、纳秒时间戳输出
[MySQL] MySQL export database
816. fuzzy coordinates
Small record of neural network learning 71 - tensorflow2 deep learning with Google Lab
Conditional variables for thread synchronization
刷题记录Day01
WPF 值转换