1. 程式人生 > >LR中exit(-1)、return -1/return 0等的區別

LR中exit(-1)、return -1/return 0等的區別

實驗環境:LR11: 程式碼:

  • vuser_init
vuser_init()
{
	lr_output_message(">>>>>>>>>> init");
	//exit(-1);
	//return -1;
	return 0;
}
  • Action1
Action1()
{
	lr_output_message(">>>>>>>>>>> 1");
	//exit(-1);
	//exit(-2);
	//exit(0);
	//exit(1);
	//return -1;
	//return 0;
//return 1; lr_output_message(">>>>>>>>>>> 2"); return 0; }
  • Action2
Action2()
{
	lr_output_message(">>>>>>>>>>> 3");
	return 0;
}
  • vuser_end
{
	lr_output_message(">>>>>>>>>>> end");
	return 0;
}

直接執行,結果如下

Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8859 (Aug 18 2010 20:14:31)  	[MsgId: MMSG-27143]
Run Mode: HTML  	[MsgId: MMSG-26000]
vuser_init.c(3): >>>>>>>>>> init
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action1.
Action1.c(
3): >>>>>>>>>>> 1 Action1.c(11): >>>>>>>>>>> 2 Ending action Action1. Starting action Action2. Action2.c(3): >>>>>>>>>>> 3 Ending action Action2. Ending iteration 1. Starting iteration 2. Starting action Action1. Action1.c(3): >>>>>>>>>>> 1 Action1.c(11): >>>>>>>>>>> 2 Ending action Action1. Starting action Action2. Action2.c(3): >>>>>>>>>>> 3 Ending action Action2. Ending iteration 2. Ending Vuser... Starting action vuser_end. vuser_end.c(3): >>>>>>>>>>> end Ending action vuser_end. Vuser Terminated.

一、當在Action1中加上 exit(-1),後直接終止迭代停止程式執行,後續程式碼均不執行

Action1()
{
	lr_output_message(">>>>>>>>>>> 1");//執行 >>>>>>>>>>> 1
	exit(-1); // 程式直接終止,跳出所有迭代和`Action`
	lr_output_message(">>>>>>>>>>> 2");//不執行
	return 0;
}
Virtual User Script started at : 2018-10-29 11:50:26
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8859 (Aug 18 2010 20:14:31)  	[MsgId: MMSG-27143]
Run Mode: HTML  	[MsgId: MMSG-26000]
vuser_init.c(3): >>>>>>>>>> init
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action1.
Action1.c(3): >>>>>>>>>>> 1 

注:exit(0)/exit(-2)/exit(2)/exit(1) 也是一樣的

二、當在Action1中加上return -1時,程式執行到此處,跳出所有Action和迭代,但會執行vuser_end

Action1()
{
	lr_output_message(">>>>>>>>>>> 1");//執行 >>>>>>>>>>> 1
	return -1;; // 程式跳出所有迭代和`Action`,但會執行 vuser_end
	lr_output_message(">>>>>>>>>>> 2");//不執行
	return 0;
}
Virtual User Script started at : 2018-10-29 12:53:49
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8859 (Aug 18 2010 20:14:31)  	[MsgId: MMSG-27143]
Run Mode: HTML  	[MsgId: MMSG-26000]
vuser_init.c(3): >>>>>>>>>> init
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action1.
Action1.c(3): >>>>>>>>>>> 1
Ending Vuser...
Starting action vuser_end.
vuser_end.c(3): >>>>>>>>>>> end
Ending action vuser_end.
Vuser Terminated.

三、當在Action1中加上return 0時,程式執行到此處,僅跳出當前Action,當前Action中後續程式碼不執行。

Action1()
{
	lr_output_message(">>>>>>>>>>> 1");//執行 >>>>>>>>>>> 1
	return 0;; // 程式僅跳出當前`Action`,後續程式碼不執行,其他Action和迭代正常執行
	lr_output_message(">>>>>>>>>>> 2");//不執行
	return 0;
}
Virtual User Script started at : 2018-10-29 13:00:46
Starting action vuser_init.
Web Turbo Replay of LoadRunner 11.0.0 for Windows 7; build 8859 (Aug 18 2010 20:14:31)  	[MsgId: MMSG-27143]
Run Mode: HTML  	[MsgId: MMSG-26000]
vuser_init.c(3): >>>>>>>>>> init
Ending action vuser_init.
Running Vuser...
Starting iteration 1.
Starting action Action1.
Action1.c(3): >>>>>>>>>>> 1
Ending action Action1.
Starting action Action2.
Action2.c(3): >>>>>>>>>>> 3
Ending action Action2.
Ending iteration 1.
Starting iteration 2.
Starting action Action1.
Action1.c(3): >>>>>>>>>>> 1
Ending action Action1.
Starting action Action2.
Action2.c(3): >>>>>>>>>>> 3
Ending action Action2.
Ending iteration 2.
Ending Vuser...
Starting action vuser_end.
vuser_end.c(3): >>>>>>>>>>> end
Ending action vuser_end.
Vuser Terminated.

注:return 1/return 2/return n... 也是一樣的