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 ...
随机推荐
- vue中操作Dom节点的方法
1.vue中ref操作dom节点 <template> <div id="app"> <div </div> <button @cl ...
- 重写LayoutParams,读取子View自定义属性
在EasyConstraintLayout内部定义一个静态类LayoutParams继承ConstraintLayout.LayoutParams,然后在构造方法中读取上面自定义的属性.我们通过裁剪的 ...
- (转)CentOS7下解决ifconfig command not found的办法
转:https://blog.csdn.net/ryu2003/article/details/78492127 注:本办法仅限于可联网的机器,即在安装时设置了IP地址和DNS可正常上网. 解决办法如 ...
- 生产环境下,oracle不同用户间的数据迁移。第三部分
任务名称:生产环境下schema ELON数据迁移至schema TIAN########################################前期准备:1:确认ELON用户下的对象状态se ...
- ubuntu 虚拟机安装vmware tools
1.打开ubuntu虚拟机,点击“虚拟机”---> "安装 vmware tools" 2.进入vmware tools光盘,将VMwaretools压缩包复制粘贴到桌面 ...
- 【SpringBoot】 Java中如何封装Http请求,以及JSON多层嵌套解析
前言 本文中的内容其实严格来说不算springboot里面的特性,属于JAVA基础,只是我在项目中遇到了,特归纳总结一下. HTTP请求封装 目前JAVA对于HTTP封装主要有三种方式: 1. JAV ...
- day15—jQuery UI之widgets插件
转行学开发,代码100天——2018-03-31 今天学习了jQuery UI的widgets插件,主要包括accordion插件 accordion插件 该插件表示折叠面板效果,点击头部展开/折叠被 ...
- MySQL 查询语句--------------进阶9:联合查询
#进阶9:联合查询 /* union 联合 合并:将多条查询语句的结果合并成一个结果 语法: 查询语句1 union 查询语句2 union..... 应用场景:要查询的结果来自于多个表,且多个表没有 ...
- < 利用Python进行数据分析 - 第2版 > 第五章 pandas入门 读书笔记
<利用Python进行数据分析·第2版>第五章 pandas入门--基础对象.操作.规则 python引用.浅拷贝.深拷贝 / 视图.副本 视图=引用 副本=浅拷贝/深拷贝 浅拷贝/深拷贝 ...
- 《STL源码剖析》——第五、六:关联容器与算法
第五章.关联容器 5.0.关联容器 标准的STL关联式容器分为set(集合)和map(映射表)两大类,以及这两大类的衍生体multiset(多键集合)和multimap(多键映射表).这些容器的底层 ...