从bash脚本启动TestNG套件 [英] Launch TestNG suite from bash script
问题描述
在我公司的Jenkins中使用testNG套件时遇到麻烦.这是设置:
I'm having trouble using my testNG suite in the Jenkins of my company. Here is the set up :
-Jenkins已安装在Linux机器上,因此我必须创建一个.sh来启动测试.
-Jenkins is installed on a Linux machine so I have to create a .sh which launch my tests.
-我在Windows上的Java Eclipse上对测试进行编码.
-I code my tests under Windows, on Eclipse in Java.
-我必须在项目中使用相对路径.
-I have to use relative path in my project.
-我使用文件blex_test_v1.xml启动测试.
-I use my file blex_test_v1.xml to launch my tests.
我确实写了一个批处理脚本,它可以正常工作而没有问题:
I did write a batch script, it works fine without problem :
我现在尝试将其转换"为.sh,这就是我目前所拥有的:
I now try to "convert" it into a .sh so this is what I have for the moment :
问题是我总是会收到此错误:
The problem is that I always get this error :
错误无法找到或加载主类org.testng.TestNG"
"Error Could not find or load main class org.testng.TestNG"
在StackOverflow上有大约6或7个关于此问题的文章,我已经阅读了所有文章,试图更改我的代码,重写它,甚至卸载所有.jar文件并将它们重新安装在我的lib中...可以没有看到问题出在哪里.
There is about 6 or 7 posts on StackOverflow about this problem, I've read all of them, trying to change my code, rewrite it, I even uninstall all .jar files and reinstall them in my lib ... Can't see where is the problem coming from.
它不能来自插件,jar文件,主类(我没有),我的不同路径或org.testng.TestNG,因为我的.bat使用相同的meta或它bash脚本有什么不同?
It can't be from the plug-in, jar files, main Class (I don't have any), my different paths or org.testng.TestNG because my .bat is working with the same meta or maybe it is different in bash script ?
暂时不使用Jenkins,我首先尝试制作一个可运行的脚本,然后被困在这里……我在做什么错?
For the moment I don't use Jenkins, I first try to make a runnable script and I'm reeeeally stuck here ... What am I doing wrong ?
谢谢!
PS:这是我的项目的架构(欣赏我的画家的技能):
PS : Here is the architecture of my project (admire my artist skills) :
我不使用maven,ant或gradle,而只是使用带有testNG和reportNG插件的eclipse中的Java
I don't use maven nor ant nor gradle, just Java in eclipse with testNG and reportNG plug-in
EDIT 2 : I used this answer to make my bash this guy says it is working fine, but it is not for me, even if I code it with ./ (still the same error as above):
java -cp ./blex_test_v1/lib/*:./blex_test_v1/bin org.testng.TestNG ./blex_test_v1/blex_test_v1.xml
我发现了另一个错字,但仍然遇到相同的错误:
EDIT 3 : I found another typo but still got the same error :
export CLASSPATH=./blex_test_v1/lib/*:./blex_test_v1/bin;
java org.testng.TestNG blex_test_v1/blex_test_v1.xml
注意:*使代码看起来像被注释,但未注释
Note : the * makes the code look like it is commented but it is not
推荐答案
几天后,我终于解决了问题,方法是在Java项目中创建一个主类,调用XML文件,然后创建该项目的可执行jar.最后,创建一个调用此jar的bash脚本.
After a couple of days I finally solved the problem by making a main class in my Java project calling the XML file, then create an executable jar of my project and in the end create a bash script calling this jar.
.sh的代码在这里(非常简单):
The code of my .sh is here (quite simple) :
java -jar Exec.jar
这篇关于从bash脚本启动TestNG套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!