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. Spring JDBCTemplate 简单使用

    Spring JDBCTemplate applicationContext.xml配置 <?xml version="1.0" encoding="UTF-8&q ...

  2. Zsh vs. Bash不完全对比解析,zsh是一种更强大的被成为“终极”的Shell

    https://www.zhihu.com/question/21418449 Mort | Zsh vs. Bash:不完全对比解析(1) 2014-10-07  bdpqlxz     Zsh和B ...

  3. 匿名函数 sorted() filter() map() 递归函数

    一. lambda() 匿名函数   说白了,从字面理解匿名函数就是看不见的函数,那么他的看不见表现在哪里呢? 其实就是在查询的时候他们的类型都是lambda的类型所以叫匿名,只要是用匿名函数写的大家 ...

  4. spring4.1.8扩展实战之四:感知spring容器变化(SmartLifecycle接口)

    本章是<spring4.1.8扩展实战>的第四篇,如果业务上需要在spring容器启动和关闭的时候做一些操作,可以自定义SmartLifecycle接口的实现类来扩展,本章我们通过先分析再 ...

  5. mariadb(三)查

    -查询基本使用(条件,排序,聚合函数,分组,分页) 1)创建一个表结构然后添加数据 create table baba (id int unsigned not null auto_increment ...

  6. Harbor - 私有企业级 Docker 镜像仓库

    GitHub 地址 容器镜像服务 Docker镜像的基本使用 Docker:企业级私有镜像仓库Harbor使用 Harbor 是基于 Docker Registry 的企业级镜像仓库,安装后的使用方法 ...

  7. 应用安全 - Windows操作系统 - 漏洞 - 汇总

    FTP弱密码 将FTP服务器的密码更改为强密码 vi /etc/vsftpd/vsftpd.conf anonymous_enable=NO #禁止匿名登录 重启ftp服务 Windows匿名用户整改 ...

  8. 关于在eclipse中配置tomcat的各种坑

    先说在windows下的,java环境什么的就不再记录了,记住装java ee之前,先要装好java se这样java ee才能顺利安装. 主要是安装好tomcat之后,在eclipse中进行配置的时 ...

  9. MySQL数据库忘记密码如何重新设置?

    前 言当我们忘记了MySQL数据库密码后,该如何重新进行设置? 操作步骤步骤1:cmd打开命名窗口 步骤2:关闭正在运行的MySQL服务(命令:net stop mysql)(如果:此时MySQL正在 ...

  10. [Linux] 011 其它权限管理命令

    1. 权限管理命令:chown 命令名称:chown 命令英文原意:change file ownership 命令所在路径:/bin/chown 执行权限:所有用户 语法:chown [用户] [文 ...