public class testjava
{
public static void main(String args[])
{
System.out.println("hello world");
}
public String getStr()
{
return "hello world";
}
public String getStr(String str)
{
return str;
}
}
/*
* LoadRunner Java script. (Build: 754)
*
* Script Description:
*
*/ import lrapi.lr;
import org.apache.log4j.*; public class Actions
{
static Logger logger = Logger.getLogger(Actions.class.getName());
int i=10; public int init() { //读取log4j属性文件
PropertyConfigurator.configure("D:\\MyEclipse Enterprise Workbench 5.1.0 GA\\eclipse\\workspace\\testjava\\bin\\log4j.properties");
return 0;
} public int action() { lr.start_transaction("事务");
testjava t=new testjava();//调用测试类
lr.message( "获取返回值:"+ t.getStr("<NewParam>")); //NewParam是loadrunner参数化设置的参数 //设置集合点
lr.rendezvous("集合点");
//设置等待时间
lr.think_time(2);
lr.end_transaction("事务",lr.PASS);
//检索运行 Vuser 的计算机的名称
String my_host = lr.get_host_name( );
lr.message( "计算机的名:"+ my_host+" "+i);
lr.log_message (lr.get_vuser_id() +" "+ t.getStr("<NewParam>")); //lr.get_vuser_id 返回当前 Vuser 的 ID
logger.info(lr.get_vuser_id() +" "+ t.getStr("<NewParam>"));
lr.enable_redirection(true); System.out.println("This is an informatory message…"); // 已重定向
// System.err.println("This is an error message…"); // 已重定向 lr.enable_redirection(false);
System.out.println("This is an informatory message…"); // 未重定向
// System.err.println("This is an error message…"); // 未重定向 return 0;
} public int end() {
return 0;
}
}
Virtual User Script started
Starting action vuser_init.
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Actions.
Notify: Transaction "事务" started.
获取返回值:1
Rendezvous 集合点
Notify: Transaction "事务" ended with "Pass" status (Duration: 0.0175).
计算机的名:ms-599008241fcd 10
-1 1
System.out: INFO (Actions.java:37) - -1 1
Notify:
System.out: This is an informatory message… Notify:
Ending action Actions.
Ending iteration 1.
Ending Vuser...
Starting action vuser_end.
Ending action vuser_end.
Vuser Terminated.
看到定义的“事务”。
log4j.rootCategory=DEBUG, stdout,R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p (%F:%L) - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=c:/log.txt
log4j.appender.R.MaxFileSize=100KB
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy MMM dd HH:mm:ss} %-5p %c - %m%n
2008 三月 02 18:06:43 INFO Actions - 7 91loadrunner 提供的.NET JAVA等语言脚本支持,为测试的灵活性、多样性提供了极大的方便。
2008 三月 02 18:06:43 INFO Actions - 16 101
2008 三月 02 18:06:43 INFO Actions - 17 121
2008 三月 02 18:06:43 INFO Actions - 13 41
2008 三月 02 18:06:43 INFO Actions - 10 181
2008 三月 02 18:06:43 INFO Actions - 18 141
2008 三月 02 18:06:43 INFO Actions - 19 151
2008 三月 02 18:06:43 INFO Actions - 6 71
2008 三月 02 18:06:43 INFO Actions - 11 1
2008 三月 02 18:06:43 INFO Actions - 9 131
2008 三月 02 18:06:43 INFO Actions - 2 191
2008 三月 02 18:06:43 INFO Actions - 12 21
2008 三月 02 18:06:43 INFO Actions - 5 51
2008 三月 02 18:06:43 INFO Actions - 15 81
2008 三月 02 18:06:43 INFO Actions - 20 161
2008 三月 02 18:06:43 INFO Actions - 3 11
2008 三月 02 18:06:43 INFO Actions - 1 171
2008 三月 02 18:06:43 INFO Actions - 8 111
2008 三月 02 18:06:43 INFO Actions - 14 61
2008 三月 02 18:06:43 INFO Actions - 4 31
欢迎光临 思步网 (http://www.step365.com/) | Powered by Discuz! X3.2 |