0

Currently in Intellij if I try to create a new file via "New > whatever", I don't see any option to choose a JUnit file. I dug deeper and found out the "Edit File Templates...". While you can add a variety of files from there to the context menu, there is no ability to choose JUnit.

enter image description here

If you browse over to "Code" tab you can see various JUnit templates. However I have no idea if these are just code generation templates instead of file generation templates. And besides, there is no option to port them to the "Files" tab.

The closest SO thread describing this issue is this and it failed to match my needs.

Mind you I am relatively new to Intellij and I come from eclipse.

P.S: I am aware you can generate tests from existing classes. I am currently trying to implement TDD so that does not answer my needs.

Fletcher
  • 621
  • 6
  • 16
  • Junit templates in "Code" tab are used while test class generation. You may change for example the "JUnit5 Test Class" template and see how the generated code have changed. Please clarify why isn't Generate test suitable for you? – Olga Klisho Jul 19 '19 at 08:14
  • @OlgaKlisho TDD dictates creating the test before the class it is about to test, hence the need to create a test by file instead of generate it from a class. – Fletcher Jul 19 '19 at 13:03
  • You may create new template in Files tab, then cmd+N on package and select the "From file template" option (in opened menu you need to select the template that you've created). – Olga Klisho Jul 22 '19 at 13:08

1 Answers1

1

While I don't have an answer for this exact question, I think there's an easier way to handle the underlying requirements (easily creating tests):

Navigate to the class you want to test and press ALT+ENTER. In the context menu, pick "Create Test":

Create Test context menu

After you choose it, you'll get a dialog with several options including the framework to use (e.g., JUnit 5, JUnit 5, TestNG), the methods you want to generate test stubs for, etc:

Test generation menu

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • What I am looking is a way to create the test before the class, as by TDD protocols. Nevertheless I have upvoted you since you may help someone else. – Fletcher Jul 18 '19 at 07:52