Unit Testing of Classes in Java
Every class can have a main method. That is a handy trick for unit testing of classes. For example, you can add a main method to the Employee class:
test.java :
import java.util.*;
import java.time.*;
class Employee
{
String name;
double salary;
LocalDate hireday;
public Employee(String n, double s, int year, int month, int day)
{
name = n;
salary = s;
}
public static void main(String[] args)
{
Employee e = new Employee("Romeo", 50000, 2003, 3, 31);
System.out.println(e.name);
}
}
After compilation javac test.java:
If you want to test the Employee class in isolation, simply execute
java Employee
If the Employee is a part of a larger application, you start the application with
java Application
and the main method of the Employee class is never executed.
这个方法可以用来调试Java子程序和Class,而不用每次都新建一个完整的Application。
Unit Testing of Classes in Java的更多相关文章
- Java Unit Testing - JUnit & TestNG
转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...
- 10 Unit Testing and Automation Tools and Libraries Java Programmers Should Learn
转自:https://javarevisited.blogspot.com/2018/01/10-unit-testing-and-integration-tools-for-java-program ...
- [Java Basics3] XML, Unit testing
What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...
- C/C++ unit testing tools (39 found)---reference
http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...
- Unit Testing of Spring MVC Controllers: “Normal” Controllers
Original link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...
- Unit Testing of Spring MVC Controllers: Configuration
Original Link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...
- Unit Testing with NSubstitute
These are the contents of my training session about unit testing, and also have some introductions a ...
- Javascript单元测试Unit Testing之QUnit
body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; } QUnit是一个基于JQuery的单元测试Uni ...
- Unit Testing a zend-mvc application
Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...
随机推荐
- 使用PHPExcel操作Excel用法实例分析
本文实例分析了使用PHPExcel操作Excel用法.分享给大家供大家参考.具体分析如下: PHPExcel下载地址:http://www.codeplex.com/PHPExcel http://w ...
- python之-框架
MVC:Model-View-Controller,中文名“模型-视图-控制器” C——Python处理URL的函数:Controller,Controller负责业务逻辑,比如检查用户名是否存在,取 ...
- Node对象的一些方法
Node对象是什么提供了 DOM的标准规范提供了Node对象,该对象主要提供了解析DOM节点树结构的属性和方法,DOM树结构主要是依靠节点进行解析,称为DOM节点树结构.Node对象是解析DOM节点树 ...
- 提高Service优先级
在onStartCommand()方法中开启一个通知,提高进程的优先级.注意:从Android 8.0(API级别26)开始,所有通知必须要分配一个渠道,对于每个渠道,可以单独设置视觉和听觉行为.然后 ...
- (转)k8s集群部署二:flannel网络
转:https://blog.csdn.net/sinat_35930259/article/details/79946146 Overlay Network模式 覆盖网络,在基础网络上叠加的一种虚拟 ...
- ruby file
E:/AutoTHCN/lib/report/generate_report/web14/20190516/LoanTool.636936123857869205_190516_140514.xlsx ...
- 第 13 章 python并发编程之io模型
一.IO模型介绍 同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)IO分别是什么,到底有什么区别?这个问 ...
- django初学---基本目录结构-配置html页面显示步骤
extra_apps 存放第三方应用,包,源码 apps -- 存放内部应用 static --存放CSS文件,JS文件,图片文件等待 media -- 存放系统里允许用户上传的图片或者文件 requ ...
- 学习:STL----优先队列
优先队列是队列的高级版,最大的特点是可以内部实现排序 优先队列的定义 优先队列内部使用堆排序,从而实现队列内一直保持着某种顺序规律(比如递增,递减等) 在使用优先队列时,首先要引入头文件:#inclu ...
- 09 (H5*) JS第7天 原型
目录 1:创建对象的3中方式 2:工厂模式创建实例对象 3: 实例对象和构造函数的关系 4:构造函数创建对象带来的问题--原型 5:原型中创建方法 6:构造函数.原型对象.实例对象的关系 7:原型对 ...