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. Linux之虚拟机里的REHL7的IP

    RHEL7最小化安装之后(桥接模式),我们查看本机IP, ip addr ifconfig 我们要修改配置文件 找到目录 找到文件,用vi编辑器打开修改配置文件 保存退出后,需要重启网络服务 只有我们 ...

  2. 【OPCAutomation】 使用OPCAutomation实现对OPC数据的访问

    折腾了一段时间研究OPC,理清了下位机.OPCServer 和OPCClient的关系和通信模型,终于能够来写一篇相关的博客了. 我们使用西门子的 S7 200 SMART作为下位机端,通过3G路由器 ...

  3. sts测试流程

    测试目的: 测试安全补丁打上了没 测试前提: 1.发货版本,user debug版本,相应安全补丁已合入,测试工具与安全补丁是对应的 2.selinux:Enable 3.连接ADB,stay awa ...

  4. 上海站赛后总结&反思

    上海站赛后总结&反思 赛后反思一下,本应该做出3~4题的场,最后只出了2题. 先回顾一下比赛,比赛开始10分钟,队友dy就想出了B题是trie树的模板题,然后让mqy码,第一次交的时候有地方打 ...

  5. 微信小程序这一块(续)

    1.设置头部的信息 通过wx.setNavigationBarTitle 详情见:https://developers.weixin.qq.com/miniprogram/dev/api/ui/nav ...

  6. IDF-CTF-图片里的英语 writeup

    题目链接:http://ctf.idf.cn/index.php?g=game&m=article&a=index&id=34 一恒河沙中有三千世界,一张图里也可以有很多东西. ...

  7. 04 - Jmeter4.x聚合报告,测试报告以及测试报告用法于解析

    聚合报告 添加方式 Thread Group    →    add    →    Listener    →    Aggregate Report 内容解析 lable: 指代当前Samples ...

  8. python之从文件中按行读取数据

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'jiangwenwen' # 从文件中按行读取数据 file = open(& ...

  9. 洛谷 P1168 中位数(优先队列)

    题目链接 https://www.luogu.org/problemnew/show/P1168 解题思路 这个题就是求中位数,但是暴力会tle,所以我们用一种O(nlogn)的算法来实现. 这里用到 ...

  10. python学习第十六天集合的关系测试

    在做数据分析的时候,要对一个集合分析,而且分析多个集合的之间的关系分析,那么用传统的循环的比较麻烦,集合提供很多方法,很容易比较多个集合的关系,并集,交集,差集,对称差集等. n1={1,2,4,6} ...