0

I have a bunch of test classes which I want to execute by running the jar file,for that purpose I am using Classpathsuite. It runs fine in the IDE,and all tests in the package are executed. but when I try to run it by jar file, I get this output. Command : java -jar projectname.jar

Time: 0.002

OK (0 tests)

Here's the code for the main class:

 @RunWith(ClasspathSuite.class)
 public class MySuite {
    public static void main(String[] args){
    JUnitCore junit = new JUnitCore();
    junit.addListener(new TextListener(printStreamObj));
    junit.run(MySuite.class);
   }
}

I have checked the jar file, and it does contain the testclasses (all of them are placed in main) so it is not an access issue. Why aren't the test classes executed?

  • Welcome to Stack Overflow. Please take the [tour] to learn how Stack Overflow works and read [ask] on how to improve the quality of your question. Then [edit] your question to include a more detailed description of the system you have. Include information like version numbers, the source code of the java files and unit tests (as a [mcve]), a description of how you build the `jar` file and a detailed description on how you try to run the Classpathsuite. – Progman Sep 17 '22 at 15:04
  • 1
    This is project build by maven/gradle? Usually tests are not added to jar. – notAPPP Sep 17 '22 at 16:07
  • @notAPPP Yes by maven. I have those classes in main folder so the classes are added to jar, just they are not getting executed. – nihal bhandary Sep 17 '22 at 16:40
  • If you are able to build jar again check if jar have: The test classes (I assume this is ok from previous project) The application code classes External dependencies required by application code (in compile scope) External dependencies required by the test code (in test scope) And plugin to bundle all, check this answer: https://stackoverflow.com/a/36047816/13523946 maybe you have Fat jar and there is onl problem with execution, but please confirm – notAPPP Sep 17 '22 at 17:00
  • @notAPPP Yes all the classes and dependencies are present in the jar, I have tried the fat jar version too. It doesnot execute. It's a very strange situation the classpath does not add the test classes at runtime when I run it from jar file, but it does so in the IDE. what could be the reason? – nihal bhandary Sep 18 '22 at 11:54

0 Answers0