Listing Java, JavaScript, and Python tests

Pablo Rivero
Sep 3, 2018 · 2 min read

In the last article, we finished identifying a Java project and listing its tests. Let’s see how I did with JavaScript and Python projects:

JAVASCRIPT PROJECTS

My main approach has been the first I described here, I search the package.json and the framework name inside of the project folder in order to identify the stack.

After that, we can simply search into the “test” folder (Mocha and Tape) or “spec” for Jasmine.

It true that is a very volatile solution, mainly because you can change the default folder, or even not use a package.json. But, for the first issue I’ll add a method which will allow to find the specified folder by the user in the settings file; and for the second one simply an exception, adding the package.json as another requirement for this app to work (besides pom.xml for Java).

PYTHON PROJECTS

In order to identify a Python project, we just look for any .py file. And, for listing, we have a very interesting approach:

After some research, I found the discover() function of the unittest library (installed by default in Python2 and 3), which allow us to find every test of a project.

It wasn’t difficult to do a little script which would create a .txt with all the test of my project:

Discover to .txt script
testList.txt

Now with Java we just have to execute the script and then read the file:

Yes, SonarLint is telling me to use a Logger…

For executing python we can also use Jython (the old JPython), an implementation of the Python language for the Java platform. But for now, I want to Keep It Simple (Stupid!), add that improvement to Trello and keep the developing going (incremental development for the win!).

Finally, I build the library, import it to my project and use it as I did in the last article:

I have a sample project with JUNIT5, Mocha and Python

The next steps would be to find how to execute these listed tests, so I can select the tests I want to be executed, and avoiding executing all of them.


You can follow the day to day work in GitHub and Trello.

Pablo Rivero

Written by

Software Engineering Student — Final Year Project

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade