Mac automation for Java-run Java programs automatically

Source: Internet
Author: User

This article is intended to help readers introduce how to run Java code locally if a test engineer gets a Mac copy

First write down the following code

Package ZLR;

Import Org.junit.Test;
public class Zlrshiyan {
@Test
public void test123 () throws exception{
System.out.print (123);
}
}
The path to the file is/USERS/ZLR/IDEAPROJECTS/ZLR/SRC/ZLR, for example, the local code can run correctly

When we thought about the same thing as windows that we wrote earlier, can Macs use Ant to execute like Windows?
1 Local Execution Java program code
Mac as a more than Windows closer to the Linux operating system, its timing tasks can certainly be executed, this article to briefly demonstrate the Mac's scheduled tasks
The first thing to do first is to use Ant to execute the Java program above, using ant as the following ant code

<?xml version= "1.0" encoding= "UTF-8"?>
<project basedir= "." Default= "JUnit and Report" Name= "Testauto" >

<!--date--
<tstamp prefix= "MyDate" >
<format property= "Day" pattern= "Yyyy-mm-dd"/>
<format property= "Time" pattern= "HH:mm:ss"/>
<format property= "DT" pattern= "Yyyy-mm-dd HH:mm:ss. SSS "/>
<format property= "dt1" pattern= "YyyyMMdd" offset= "-1" unit= "Day"/>
<format property= "DT2" pattern= "YyyyMMdd" offset= "-3" unit= "Day"/>
<format property= "DT3" pattern= "yyyyMMdd" offset= "0" unit= "Day"/>
<format property= "Dt4" pattern= "Yyyymmddhhmmss"/>
</tstamp>

<!--parameter definition--
<property name= "appname" value= "Testauto"/>
<property name= "Build.dir" value= "/users/zlr/desktop/autotest"/>
<property name= "Build.class.dir" value= "${build.dir}/target/production/zlr/"/>
<property name= "Build.lib.dir" value= "${build.dir}/lib"/>
<property name= "Build.report.dir" value= "${build.dir}/report/${appname}_jenkins"/>
<property name= "Build.report.name" value= "Jenkins"/>
<property name= "Build.report.ip" value= "10.10.81.108"/>
<property name= "Build.report.remote" value= "E:/apache-ant-1.9.4/bin/apache-tomcat-6.0.30/webapps/report"/>


<target name= "JUnit and Report" Depends= ""
description= "Run test and send Report" >
<!--Delete the original report folder first--
<delete dir= "${build.report.dir}"/>
<!--Create a new report folder--
<mkdir dir= "${build.report.dir}"/>

<junit printsummary= "on" fork= "true" showoutput= "true" >
<sysproperty key= "file.encoding" value= "GBK"/>
<formatter type= "xml" usefile= "true"/>
<classpath>
<fileset dir= "${build.lib.dir}" includes= "*"/>
<pathelement path= "${build.class.dir}"/>
</classpath>
<batchtest todir= "${build.report.dir}" >
<fileset dir= "${build.class.dir}" >
<include name= "Zlr/zlrshiyan.class"/>
</fileset>
</batchtest>
</junit>

<!--report Output path--
<junitreport todir= "${build.report.dir}" >
<fileset dir= "${build.report.dir}" >
<include name= "Test-*.xml"/>
</fileset>
<report format= "Frames" todir= "${build.report.dir}"/>
</junitreport>

</target>

</project>

The ant points above and the previous introduction of Windows can be said to be very similar, so no longer repeat, interested students and questions can go to browse http://www.cnblogs.com/xuezhezlr/p/7725301.html

Here is a feature of Mac, is the installation of Java

If you use a normal Java installation, a box appears and then automatically installs to the system's hard disk, but one problem is that it is not easy to access that path, so it is difficult to operate it

While the ant debugging process can be seen, all the way is not imported Java environment variables, just rely on local Java variables to implement the Mac so, the control of the Java variable is very important, so https://support.apple.com/kb/DL1572 Locale=en_us&viewlocale=en_us This is my highly recommended Java installation address, it is recommended to use this to install

The big difference from Windows is that Windows uses. bat files to execute ant commands, while Macs use. sh files to execute ant, which is also where Mac notebooks compare Linux-like

Here is the local execution result

2 using Crontab to execute code at timed intervals
After manual execution naturally we think of automatic code execution, because the Mac is very similar to Linux on the kernel, so here is the more prevalent crontab on Linux to execute Java code on a regular basis
Enter Crontab-e, and then enter our next line of text where it appears and save

* * * * * source/users/zlr/.bash_profile &&/users/zlr/desktop/autotest/runant.sh

Save remember, to use wq! Here, let's talk about this statement.

00 21 * * These are time-of-day, meaning that each time the condition is fulfilled, the following line of the shell statement is executed.

The 1th column represents minutes 1~59 per minute with * or */1
The 2nd column represents the hour 1~23 (0 means 0 points)
The 3rd column represents the date 1~31
The 4th column represents the month 1~12
5th Column Identification Number Week 0~6 (0 = Sunday)

And here's the * refers to this kind of search conditions can be ignored, such as only the first two columns above is not *, then the meaning is every night 9 o'clock to execute, http://blog.csdn.net/h514476785j/article/details/52512354 here have a more detailed explanation

But Java is also a feature of environment variables, so the following statements are Source/users/zlr/.bash_profile &&/users/zlr/desktop/autotest/runant.sh

The first thing to do is execute the SOURCE/USERS/ZLR/.BASH_PROFILE load environment variable and execute the ant command in the/users/zlr/desktop/autotest/runant.sh, intermediate && Symbol to link, another way is to write multiple shell statements in Runant to execute

The above is the simple automation of the Mac, everybody refueling, I study the Jenkis if there is a result to send out



Mac automation for Java-run Java programs automatically

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.