I created a new skeleton Leiningen project using Java 1.8
in IntelliJ IDEA 2018.2.6 (Build #IU-182.5107.16)
.
I got an Error: Could not find or load main class cucumber.api.cli.Main
. I wanted to use jUnit instead so I didn't try fix the Cucumber dependency.
File > Project Stucture > Module:. Verified that the test folder is marked as Tests.
File > Project Structure > Libraries > + > From Maven: Added junit:junit:4.12
with Transitive dependencies and JavaDocs to my module.
Run > Edit Configurations:
When I run all tests, I am presented with an Empty test suite message.
I have tried rebuilding the project, checking for IntelliJ updates, invalidating the cache, using an absolute path in the Working directory in the project configurations modal.
When I run lein test
in the terminal, the sample test is detected and the assertion is printed out.
Essentially, how do I create a new Leiningen Clojure project in Intellj using the jUnit test runner detects and runs my tests?
If you need it, I have pushed the source code of my example project to Github.
I no longer use Leiningen templates to create a new project (e.g. lein new app XXXXX
). Instead, I have a template project that I clone using git
, and I use as the basis for new Clojure and ClojureScript projects:
Example of starting a new project:
> git clone https://github.com/io-tupelo/clj-template.git myproj
Cloning into 'myproj'...
At this point, you can edit the project.clj
and the source files to change and/or add namespaces, etc.
I don't create projects from within IntelliJ. I create them at the command line and then add them to IntelliJ/IDEA + Cursive.
~/tmp/demo > lein new app sample
Generating a project called sample based on the 'app' template.
~/tmp/demo > cd sample
~/tmp/demo/sample > ls -al
total 56
drwxrwxr-x 6 alan alan 4096 Nov 18 21:19 ./
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 ../
-rw-rw-r-- 1 alan alan 766 Nov 18 21:19 CHANGELOG.md
drwxrwxr-x 2 alan alan 4096 Nov 18 21:19 doc/
-rw-rw-r-- 1 alan alan 99 Nov 18 21:19 .gitignore
-rw-rw-r-- 1 alan alan 136 Nov 18 21:19 .hgignore
-rw-rw-r-- 1 alan alan 11219 Nov 18 21:19 LICENSE
-rw-rw-r-- 1 alan alan 359 Nov 18 21:19 project.clj
-rw-rw-r-- 1 alan alan 463 Nov 18 21:19 README.md
drwxrwxr-x 2 alan alan 4096 Nov 18 21:19 resources/
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 src/
drwxrwxr-x 3 alan alan 4096 Nov 18 21:19 test/
Then within IntelliJ do
File -> New -> Project from existing sources....
in the pop-up window, navigate to the new dir and double-click on the project.clj
file.
~/tmp/demo.sample
)sample:0.1.0-SNAPSHOT
(this is taken from project.clj
)sample
)Finish
At this point, you can edit project.clj
to add JUnit deps or anything else you want. This will then determine any mods you need to make in the ./test
subdir tree.
After doing
lein new app sample
you will see in sample/project.clj
(defproject sample "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]]
:main ^:skip-aot sample.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
The above is just the bare bones.
For more info, please see: