Getting started with TestNG in IntelliJ?

Hi all, I can't help but think I'm missing something obvious. I'm new to this IDE, and have failed to discover how to create a TestNG test. I just downloaded the current community editionl, and created a simple Java class with a trivial method in. Then I created another class and annotated a method with @Test. This shows in red, and does not offer the suggestion of importing the org.testng annotation. I tried to add the TestNG library, and there's nothing on the list, and I can't see any other way to get it there. Am I supposed to manually install this? I got the very distinct impression that this was "built in" to IntelliJ, and I don't want to do it the wrong way. All the docs I managed to find seem to imply it should "just work"

Suggestions?

TIA
Simon

6 comments

Hello.

Some hints that may help:
1. Is TestNG-J plugin enabled? Please see Settings / Plugins.
2. With that plugin, I typically just put the caret to a class name, Alt+Enter, use Create Test intention. Select TestNG in the dialog and use all "Fix" suggestions.

Regards,
Alexander.

0

Hmm, thanks, this moved me forward, but now I discover the installation is horribly screwed up in some way. I'll move this to a new thread, but the IDE reports that it cannot find symbols from java.lang (like "String" and "Exception"). Clearly something is horribly wrong with this!

Thanks Alexander...

0

Check JDK definition.

Project Structure dialog / Modules / your module / Dependencies tab / Module SDK.
If it's "Project SDK" and red, check project SDK: the same dialog / Project / Project SDK.
If it's undefined or so, try New, Edit buttons, or Project Structure dialog / SDKs section.
Anyway, all issues are in that dialog.

Regards,
Alexander.

0

Oh, never mind. Turns out that accidentally running this IDE as root has some incredibly strange consequences!

Thanks, that alt-enter trick was all I needed.

One remaining question, probalby similarly basic. If I failed to click the "Fix" button that adds the library to the project, where would be the manual way to add that (and other libraries)?

Many thanks again!

0

It adds the following jar: (IDE installation)/plugins/testng/lib/testng.jar

The module dependencies are on page I've mentioned before: Project Structure / Modules / the module / Dependencies - here is the place to add more jars or directories you need.

Regards,
Alexander.

0

Aha. Many thanks. Sorry for asking trivial questions; it's amazing how hard it can be to get used to something that's just plain laid out differently from what you're accustomed to! Really appreciate you taking the time to rescue me.

Cheers,
Simon

0

Please sign in to leave a comment.