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. bzoj1964: hull 三维凸包

    传送门 二维平面四个点求凸包面积->任选三个点面积之和/2 三维平面五个点求凸包体积->任选四个点体积之和/2 二维平面三个点面积->二个二维向量行列式值的绝对值/2 三维平面四个点 ...

  2. UE4开发PSVR游戏的常见问题

    Failed to connect to file server at xxx.xxx.xxx.xxx. RETRYING in 5s解决办法:PS4 Devkit 中 Settings->De ...

  3. 减轻Temporal AA 的 拖影问题(ghosting)

    Temporal AA 效率高,但是有拖影等问题,UE4中可以如下修改减轻拖影问题: 搜索到PostProcessTemporalAA.usf文件,打开,找到 #define AA_DYNAMIC_A ...

  4. NSProxy实现AOP方便为ios应用实现异常处理策略

    前段时间关注过objc实现的AOP. 在GitHub找到了其中的两个库:AOP-in-Objective-C 和 AOP-for-Objective-C 第一个是基于NSProxy来实现的:第二个是基 ...

  5. MySQL 基准测试

    这是<高性能 MySQL(第三版)>第二章的读书笔记. 基准测试(benchmark)是针对系统的压力测试,用于掌握系统行为或重新系统的某个状态.sysbench 是常用的 MySQL 基 ...

  6. upc组队赛16 Winner Winner【位运算】

    Winner Winner 题目链接 题目描述 The FZU Code Carnival is a programming competetion hosted by the ACM-ICPC Tr ...

  7. org.apache.hadoop.hive.ql.exec.DDLTask. MetaException错误问题

    下载 http://www.java2s.com/Code/Jar/m/Downloadmysqlconnectorjavacommercial517binjar.htm 放到lib目录下,删除原本的 ...

  8. 10、numpy——位运算

    NumPy 位运算 NumPy "bitwise_" 开头的函数是位运算函数. NumPy 位运算包括以下几个函数: 函数 描述 bitwise_and 对数组元素执行位与操作 b ...

  9. 牛客练习赛27-----C.水图(DFS求最长路径)

    传送门 来源:牛客网题目描述:小w不会离散数学,所以她van的图论游戏是送分的小w有一张n个点n-1条边的无向联通图,每个点编号为1~n,每条边都有一个长度小w现在在点x上她想知道从点x出发经过每个点 ...

  10. CSV的规范与使用

    CSV可以通过Excel打开,数据格式比较小,通过记事本打开一个CSV文件, 便知道在csv里面,每一个单元格的数据都是通过逗号来分割的.所以在csv里面切记:单元格数据不要出现逗号 格式: 第一行: ...