Running individual tests from a jar under IntelliJ 2016

Answered

I teach a large intro CS class, and in transitioning from 14 to 16, have hit a wall because I cannot work out how to  straightforwardly execute individual tests from within a jar under IntelliJ 16.

For one important part of my class, I distribute to the students jars with compiled unit tests that I've prepared for them (class files, not sources).  They then write their code against these tests.

Previously, I instructed students to:

  1. Create their project
  2. Get JUnit4 in their class path,
  3. download then add my jar to their project's dependencies, and
  4. run a specific test within the jar using the context menu when selecting the given test, and choosing "Run..."

This worked just great.   I distributed jars with many tests; the students wrote code, added my jar and then tested their code against my tests by right-clicking on the test in question and selecting "Run...".

I've now updated to IntelliJ 2016 and cannot get this to work.  The context menu for a test within the distributed jar does not offer "Run..." any longer.

I have managed two things:

  1. to manually construct run configurations for each test, but this is untenable when the number of tests is >> 10 and I have > 300 students of varying skill levels
  2. to add the jar as a project source and label it as a test source.  This gives me the "Run..." option under the context menu when right clicking on the test within the jar, but leads to the error message: "Error:resources: "xxx/IdeaProjects/yyyy/out/test/yyyy/. (Is a directory)"

I've spent quite a few frustrated hours on this, and would appreciate any insight any of you might have.    It's not at all obvious why the 14->16 upgrade should have wreaked such havoc with a central part of my large, carefully prepared, Java class. 

What am I doing wrong??

Thanks for any help you may have.

8 comments
Comment actions Permalink

Hi Steve,

 

If you want to start one method/class, it should work. Please attach your jar (or send it to me) so we can reproduce the problem here.

Thanks,

Anna

0
Comment actions Permalink

Thanks Anna.

I've put a trivial jar at this link

It contains a single trivial test for hello world.   If I take that jar and add it to a project (Project Structure.. -> Modules -> Dependencies -> +). The jar is added under External Libraries, just as it was under version 14.   Inspecting the jar shows HelloTest with an icon that I understand indicates that it is executable:

However, when clicking on HelloTest, the context menu does not give me an option to run it.   Under version 14, this worked straightforwardly.

If you could point out what I've done wrong here, or what's changed in version 16, I'd appreciate it.

Thank you.

 

0
Comment actions Permalink

In the editor, there is an option to run your test, in the project view it's disabled as tests are normally supposed to be inside your project, not inside library. 

Sorry for the inconvenience,

Anna

0
Comment actions Permalink

I am sorry, I don't understand.

1.  This worked fine under IntelliJ 14, it does not now.  Why?

2.  Please consider the case where tests are distributed as a jar.   How does one run these tests?  I have no desire for the jar to be an external library (that happens to be a natural way to add a jar).   I simply want to run tests that are provided in a jar.

3.  You say that "In the editor, there is an option to run your test".  Could you explain where I might find this option?

Thanks.

0
Comment actions Permalink

3. If you dbl click on the file in project view, IDEA would open editor with decompiled code. If you right click on a class name, you'll see options to run/debug tests, etc.

1. 2.

The options were removed from project view as normally people don't run code from library and were complaining that there are additional items in the menu and some slowness due to this items, so they were removed.

Tests belong to the project, not as external additional to it. I believe that if you would create a project on github or elsewhere and would provide tests inside the project, it would be much easier to maintain and explain to the students. E.g. courses on Cursera normally provide some source stubs and tests inside a project, not as additional library. What do you think?

 

0
Comment actions Permalink

Thanks Anna.

I can successfully use option 3.  It's not pretty, but it works.

With respect to two; the context here is teaching.   For many elements of the teaching I, of course, do exactly as you say---I provide the students with a project (as a git repo), which comes complete with tests.   However, I also want to be sure that students can *create* projects and add tests (provided externally).    It is entirely reasonable that tests would be captured as an external artefact against which one wants to test one's own code (there are many examples of this in the real world).   I've been doing this for years (originally in eclipse, then in intelliJ) and it has worked extremely well until now.

So having had 3 and 1 answered, my question now is, how do you recommend that externally provided tests be integrated into a project?   As I say, this used to be straightforward, but does not seem to be now.   I'm quite happy to do things differently, but the bottom line is that I want to be able to provide externally generated tests, and then have them brought into other projects and used there.  If you can suggest a better way to do it than what I'm doing, I'd be very happy to hear it.

0
Comment actions Permalink

Ok, as I can't find now those complaints I've reverted that optimization. Let's see how it would work.

Please watch https://youtrack.jetbrains.com/issue/IDEA-158464 if there would be any changes in the future, there would be some comments there.

 

Thanks,

Anna

0
Comment actions Permalink

Thank you Anna.   Much appreciated.

0

Please sign in to leave a comment.