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的更多相关文章

  1. Java Unit Testing - JUnit & TestNG

    转自https://www3.ntu.edu.sg/home/ehchua/programming/java/JavaUnitTesting.html yet another insignifican ...

  2. 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 ...

  3. [Java Basics3] XML, Unit testing

    What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...

  4. C/C++ unit testing tools (39 found)---reference

    http://www.opensourcetesting.org/unit_c.php API Sanity AutoTest Description: An automatic generator ...

  5. Unit Testing of Spring MVC Controllers: “Normal” Controllers

    Original link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...

  6. Unit Testing of Spring MVC Controllers: Configuration

    Original Link: http://www.petrikainulainen.net/programming/spring-framework/unit-testing-of-spring-m ...

  7. Unit Testing with NSubstitute

    These are the contents of my training session about unit testing, and also have some introductions a ...

  8. Javascript单元测试Unit Testing之QUnit

    body{ font: 16px/1.5em 微软雅黑,arial,verdana,helvetica,sans-serif; }           QUnit是一个基于JQuery的单元测试Uni ...

  9. Unit Testing a zend-mvc application

    Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...

随机推荐

  1. 有关CSS的一些事

    看到两篇关于CSS的文章,总结的非常好.因为没有那个网站的账号,没法收藏转发,所以把链接贴在这里,分享给大家.这两篇文章对于初学CSS的人来说,总结得很精炼准确,而且通俗易懂.推荐~ 有关CSS的一些 ...

  2. C# 修改注册表立即刷新 转载

    修改注册表后不重启计算机并生效,代码如下:const int WM_SETTINGCHANGE = 0x001A; const int HWND_BROADCAST = 0xffff;IntPtr r ...

  3. ACM2014-04训练计划

    这是我写的第一篇博文,先简单说说今天的状态吧,毕竟我的第一篇博文是今天诞生的.这学期开学以来各种乱忙,开学初准备高数竞赛决赛,而后有一段时间疯狂学习英语,一直到前几天国创项目中的任务,准备数模竞赛,上 ...

  4. Not a Number (NaN)

    NaN can be produced by: 1. 0/0 2. Inf - Inf 3. Inf/Inf 4. 0*Inf 5. rem(x,y), where y=0 or x=Inf

  5. git清空远程仓库

    需求背景:因为用jenkins连接了git仓库,有时候job构建出现问题,需要排查问题,但是呢,真实的项目代码量非常pang大,所以就需要建1个测试仓库,使用最少量的代码能复现自己的问题就好. 这就需 ...

  6. Centos7配置定时重启服务器

    Crontab是一个很方便的在unix/linux系统上定时(循环)执行某个任务的程序. 用 service crond status 查看 crond服务状态,如果没有启动则 systemctl s ...

  7. JavaWeb防止用户的重复请求提交

    这里实现这个重复提交的防止,是通过在一个FIlter过滤器中生成一个令牌token,保存在Session域中,然后在对这个token加密得到ciphertext(密文),将密文保存在request域中 ...

  8. CentOS利用Lua访问Redis

    首先确保你编译的Lua是支持链接外部动态链接库的.因为在对Redis进行访问时是需要使用socket通信的, 而这依赖于外部的C语言写的动态连接库. 首先,这里先下载Redis的Lua客户端访问包re ...

  9. c.vim

    放在 /usr/share/vim/vim80/syntax/c.vim 最后: syn match cFunctions "\<[a-zA-Z_][a-zA-Z_0-9]*\> ...

  10. 最短路 dijkstra算法

    题目 给定n个点的带权有向图,求从1到n的路径中边权之和最小的路径. dijkstra实现方法 用dist[i]表示i这个点到原点的最短距离,一开始初始化为无穷大,然后将原点设为0. 用ok[i]表示 ...