Easymock 简明教程
EasyMock - Environment Setup
本教程将指导你在 Windows 和 Linux 系统上设置 EasyMock 的过程。只需执行一些简单步骤,即可轻松安装 EasyMock 并将其与当前的 Java 环境集成,无需任何复杂的设置。在安装时需要用户管理。
This chapter takes you through the process of setting up EasyMock on Windows and Linux based systems. EasyMock can be easily installed and integrated with your current Java environment following a few simple steps without any complex setup procedures. User administration is required while installation.
System Requirements
JDK |
Java SE 2 JDK 1.5 or above |
Memory |
1 GB RAM (recommended) |
Disk Space |
No minimum requirement |
Operating System Version |
Windows XP or above, Linux |
让我们现在继续执行安装 EasyMock 的步骤。
Let us now proceed with the steps to install EasyMock.
Step 1: Verify your Java Installation
首先,你的系统中需要安装 Java 软件开发工具包 (SDK)。要验证这一点,请根据所使用的平台执行以下两个命令。
First of all, you need to have Java Software Development Kit (SDK) installed on your system. To verify this, execute any of the two commands depending on the platform you are working on.
如果 Java 安装已正确完成,则它将显示 Java 安装的当前版本和规范。以下表中给出了一个示例输出。
If the Java installation has been done properly, then it will display the current version and specification of your Java installation. A sample output is given in the following table.
Platform |
Command |
Sample Output |
Windows |
Open command console and type: >java –version |
java version "11.0.11" 2021-04-20 LTS Java™ SE Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.11+9-LTS-194, mixed mode) |
Linux |
Open command terminal and type: $java –version |
java version "11.0.11" 2021-04-20 LTS Open JDK Runtime Environment 18.9 (build 11.0.11+9-LTS-194) Open JDK 64-Bit Server VM (build 11.0.11+9-LTS-194, mixed mode) |
-
We assume the readers of this tutorial have Java SDK version 11.0.11 installed on their system.
-
In case you do not have Java SDK, download its current version from https://www.oracle.com/technetwork/java/javase/downloads/index.html and have it installed.
Step 2: Set your Java Environment
设置环境变量 JAVA_HOME 以指向计算机上安装 Java 的基本目录位置。例如,
Set the environment variable JAVA_HOME to point to the base directory location where Java is installed on your machine. For example,
Sr.No. |
Platform & Description |
1 |
Windows Set JAVA_HOME to C:\ProgramFiles\java\jdk11.0.11 |
2 |
Linux Export JAVA_HOME = /usr/local/java-current |
将 Java 编译器位置的完整路径附加到系统路径。
Append the full path of Java compiler location to the System Path.
Sr.No. |
Platform & Description |
1 |
Windows Append the String "C:\Program Files\Java\jdk11.0.11\bin" to the end of the system variable PATH. |
2 |
Linux Export PATH = $PATH:$JAVA_HOME/bin/ |
如上所述,从命令提示符执行命令 java -version 。
Execute the command java -version from the command prompt as explained above.
Step 3: Install EasyMock Library
从 https://easymock.org/ 下载最新版本的 EasyMock,然后将其内容解压到文件夹中,你的 Java 程序可以从该文件夹链接到所需的库。让我们假设这些文件被收集在 C 驱动器的文件夹中。
Download the latest version of EasyMock from https://easymock.org/ and unzip its contents to a folder from where the required libraries can be linked to your Java program. Let us assume the files are collected in a folder on C drive.
将必需的 jars 的完整路径添加到 CLASSPATH,如下所示。
Add the complete path of the required jars as shown below to the CLASSPATH.
Sr.No. |
Platform & Description |
1 |
Windows Append the following strings to the end of the user variable CLASSPATH − C:\easymock\easymock-4.3.jar; |
2 |
Linux Export CLASSPATH = $CLASSPATH: /usr/share/easymock\easymock-4.3.tar: |
Step 4: Download JUnit Archive
从 Github 下载最新版本的 JUnit jar 文件。将文件夹保存在 C:\>Junit 位置。
Download the latest version of JUnit jar file from Github. Save the folder at the location C:\>Junit.
OS |
Archive name |
Windows |
junit4.13.2.jar, hamcrest-core-1.3.jar |
Linux |
junit4.13.2.jar, hamcrest-core-1.3.jar |
Step 5: Set JUnit Environment
设置 JUNIT_HOME 环境变量,使其指向计算机上存储 JUnit jar 的基本目录位置。下表显示了如何在不同的操作系统上设置此环境变量,假设我们已将 junit4.13.2.jar 和 hamcrest-core-1.3.jar 存储在 C:>Junit 中。
Set the JUNIT_HOME environment variable to point to the base directory location where JUnit jars are stored on your machine. The following table shows how to set this environment variable on different operating systems, assuming we’ve stored junit4.13.2.jar and hamcrest-core-1.3.jar at C:\>Junit.
OS |
Output |
Windows |
Set the environment variable JUNIT_HOME to C:\JUNIT |
Linux |
export JUNIT_HOME=/usr/local/JUNIT |
Step 6: Set CLASSPATH Variable
设置 CLASSPATH 环境变量以指向 JUNIT jar 位置。下表显示了如何在不同的操作系统上完成此操作。
Set the CLASSPATH environment variable to point to the JUNIT jar location. The following table shows how it is done on different operating systems.
OS |
Output |
Windows |
Set the environment variable CLASSPATH to %CLASSPATH%;%JUNIT_HOME%\ junit4.13.2.jar;%JUNIT_HOME%\hamcrest-core-1.3.jar;. |
Linux |
Export CLASSPATH=$CLASSPATH:$JUNIT_HOME/ junit4.13.2.jar:$JUNIT_HOME/hamcrest-core-1.3.jar:. |