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. ASP.NET MVC3.0 标签提交

    [HttpPost] [ValidateInput(false)] public ActionResult UpdateInformationData(ITMovingData p_data) { p ...

  2. BaseFragment 基类代码

    public abstract class BaseFragment extends Fragment implements IBaseView { private List<BasePrese ...

  3. POI 单元格类型CellType

    1.单元格类型 单元格的内容决定了单元格的类型,POI中定义的7种单元格类型: 2.示例 cell_0.setCellType(CellType.STRING);//字符串 日期数据对应的单元格类型是 ...

  4. ST表——————一失足成千古恨系列2

    在此先祝自己这个系列写的越少越好qwq(保证不超过4篇(flag已立)) 考试原题:(绝壁是看完复联出的) 第一反应:线段树??不对,是st表.嗯,没错.哎,st表咋写来着??完了凉了. 结果:写暴搜 ...

  5. EntityFramework经典数据访问层基类——增删改查

    namespace StudentSys.DAL { public class BaseService<T>:IDisposable where T:BaseEntity,new() { ...

  6. 【桶哥的问题——吃桶-简化版】【洛谷p2671】求和

    求和=>[链接] 题目相较起_rqy出的要简单很多,来自noip普及组2015 化简这个式子:x+z=2y,故x与z mod 2同余,因此和桶哥的问题——吃桶一样的思路就可以做出来啦qwq: # ...

  7. kmp(暴力匹配)

    http://poj.org/problem?id=3080 Blue Jeans Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  8. Linux Interactive Exploit Development with GDB and PEDA

    Exploit Development Process● Occupy EIP● Find the offset(s)● Determine the attack vector● Build the ...

  9. BZOJ 5450 轰炸 (强连通缩点+DAG最长路)

    <题目链接> 题目大意: 有n座城市,城市之间建立了m条有向的地下通道.你需要发起若干轮轰炸,每轮可以轰炸任意多个城市.但每次轰炸的城市中,不能存在两个不同的城市i,j满足可以通过地道从城 ...

  10. K The Right-angled Triangles

    链接:https://ac.nowcoder.com/acm/contest/338/K来源:牛客网 题目描述 Consider the right-angled triangles with sid ...