I've been writing test code in Python for the last few weeks. Although it's been great to have Perl and Java as my predominant testing languages, it is nice to try a new scripting language on for size.
I first used Python on Linux and this last week - due to testing requirements - I needed to use it on Windows.
Python Installation :
Installing Python is pretty straightforward. Go to python.org. and download it. Installation is very easy.
After the install, I needed to add the Python to the System Path.
Pip and Pytest Installation :
Pip seemed a little different to install -vs- Linux. With Linux I could install with yum and call pip directly. To use Pip on Windows I had to call it through Python first
Installing Pytest then required me calling Python to call pip and then install PyTest. See below:
python -m pip install pytest
With Pytest installed I needed to incorporate it into my Python test class:
1) Import PyTest in the Python script using : import pytest.
2) Use an assert statement for test results.
3) Place the test statements in a test method (def testSomething(): ) For the tests to work correctly with JUnit output I needed to put the asserts in a test method.
4) Create JUnit output for Jenkins. When I did run my basic test class without outputting to an XML file it seemed to work just fine, but if I wanted to get results to Jenkins I needed to get an XML file for Jenkins to read.
5) Once I solved the above issues I needed to make sure a JUnit XML file was created. This is how I called it below:
python -m pytest scripts\CheckMSIBuildStatus.py --junitxml=results.xml
Friday, May 08, 2015
Tuesday, May 05, 2015
Running a java test class in a maven project on the command line
Sometimes I need to write a quick one-off Java test class against a developer's maven project or class within a maven project.
Easy to do locally on my Mac but my Mac is not a production environment.
In this case this necessitates that I run this test class on a remote machine (UNIX or Windows) where I'd rather not setup a full development environment and most likely have command line access.
Given a minimal production environment the requirements are : I can compile the developer's class, supporting classes and libraries, my test class, and then test the resulting service; in this case a small micro service the developer created.
In this case this necessitates that I run this test class on a remote machine (UNIX or Windows) where I'd rather not setup a full development environment and most likely have command line access.
Given a minimal production environment the requirements are : I can compile the developer's class, supporting classes and libraries, my test class, and then test the resulting service; in this case a small micro service the developer created.
Pre-requisites, in my case, needed on the remote machine are :
1) Java
2) GIT
3) Maven
4) If needed, the service deployed and running under systemd.
Once I have the first three components installed, I clone the GIT repository and then try to build the maven project, usually with a mvn clean install -Dmaven.test.skip=true.
If I have any dependencies to this project, I try to use a library manager referenced in a settings.xml file under .m2 (like Artifactory) to make the project compile.
If I have any dependencies to this project, I try to use a library manager referenced in a settings.xml file under .m2 (like Artifactory) to make the project compile.
If this succeeds, I try to compile my stand-alone test class. Since I'd rather not run the developer's unit integration tests I run this command :
mvn install -DskipTests
This allows my class to compile. If this works I then I run this command :
This allows my class to compile. If this works I then I run this command :
mvn exec:java -Dexec.mainClass="com.[path to my test class].[my test class name]" -Dexec.classpathScope=test -e
Running this command allowed me to launch the Java driver program that then - in this case - created a new instance of the developer's monitor class that would run in it's own Thread through Runnable, which I could subsequently test.
Subscribe to:
Posts (Atom)
Exploring ELK (Elastic) Stack for hack-a-thon
At my current gig, our group finally got to do hack-a-thon week and I joined a team project that tied together a few of the technologies I...