This tutorial will show you how to build, run and test progsbase projects using IntelliJ IDEA. You can use an existing project as a template for a new progsbase project. So, using this tutorial you can work on existing projects or create new projects.
Go to the progsbase library repository and click on one of the libraries from the list. For example, select the JSON library. Scroll down and find the download tab. Download the "Java Project Package". This will download a zip file with the source code of the project.
Unzip the project somewhere on your machine; for example, by running the following command:
unzip JSON-project-package.zip
A progsbase project is located in a folder. For the JSON library this folder is called JSON
. Within this folder is a folder with the same name as the project. For example, this project is named JSON, so there is a folder named JSON. Inside this folder are two folders. The two folders are main
and test
. main
contains the source code of the library, and test
contains the tests. There is also a file called info.json
. This file contains the specifications of the progsbase library. Learn more about it in a separate article.
Start IntelliJ IDEA and open the project directly. For JSON this folder is called JSON
and contains a single folder called JSON
.
Then, open the folder with the project name, in this case JSON
. Inside are two folders and a file. Right click on the folder main
and select "Mark Directory as" and then "Sources Root". Next, do the same with test
but select "Test Sources Root".
The progsbase client is used to import the dependencies. Right click the folder with the project name JSON
and select "Open in terminal". Then run:
progsbase importdeps Java IDE
Learn how to install and setup the progsbase client here.
The code of the dependencies are downloaded and placed in JSON/imports
. A new folder shows up in the project called imports
. Right click it, select "Mark Directory as" and then "Generated Sources Root".
Next, make a folder for the Java byte code. Let's place it in target
. Right click the root folder, in this case JSON
. This is the top most JSON, and not the one containing main
and test
. Select New
, then Directory
. Name the directory target
.
In the top menu, select "Build", then "Build Project". You will get an error saying a Java SDK has not been configured. Click "OK", and you will get a windows where you can configure one. Under "Project SDK" select one. If one is not available, configure one using "New ...". Under "Project language level" select 7 or any higher level supported by your SDK. Finally, under "Project compiler output" write the full path of the target
folder created earlier.
Now the project should build successfully. In the top menu, select "Build", then "Build Project". You should get a message on the bottom of the IDE saying "Compilation completed successfully".
Next, make a file for running the unit tests. Let's place it in unitTestRunner
. Right click the root folder, in this case JSON
. This is the top most JSON, and not the one containing main
and test
. Select New
, then Directory
. Name the directory unitTestRunner
. Right click unitTestRunner
, select "Mark Directory as" and then "Test Sources Root".
Inside, create a class called TestRunner
. Fill it with the following code:
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestRunner {
@Test
public void runTest(){
double failures;
failures = tests.tests.test();
assertEquals(0, (int)failures);
}
}
Set the cursor on @Test
and select the lightbulb icon. Click on "Add JUnit 5.0 to classpath". Click OK.
The development environment has not been fully set up and the code built. Right click unittestrunner/Testrunner
and select "Debug TestRunner". You should see a green check mark in the IDE showing that all tests passed.
You can use the progsbase client to check for compatability with progsbase. Right click on JSON/JSON
and select "Open in terminal". Run the following:
progsbase analyze
If it returns nothing, it means the code is compatible with progsbase.
Now you have what you need to develop, test and analyze progsbase code.
We would be more than happy to help you. Our opening hours are 9–15 (CET).
📞 (+47) 93 68 22 77
Nils Bays vei 50, 0876 Oslo, Norway