0

I have some TestNG based LeanFT test cases and try to generate jar file. I use IntelliJ IDEA to set artifact's details under File -> Project Structure -> Project Settings -> Artifacts -> Jar -> From modules with dependencies. I select classname, but get error, that is not acceptable.

enter image description here

UPDATE 2018.05.03. I created main method in a new class, but got same error message.

import org.testng.TestNG;
import org.testng.xml.Parser;
import org.testng.xml.XmlSuite;
import org.xml.sax.SAXException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.util.List;

public class LeanFTest {
    public void main() throws IOException, SAXException, ParserConfigurationException {
        TestNG testNG = new TestNG();

        String xmlFileName = "testng.xml";
        List<XmlSuite> suite = (List<XmlSuite>)(new Parser(xmlFileName).parse());
        testNG.setXmlSuites(suite);

        testNG.run();
    }
}
plaidshirt
  • 5,189
  • 19
  • 91
  • 181
  • maybe a dup of https://stackoverflow.com/questions/12464637/why-is-my-class-not-acceptable ? – Aydin K. May 02 '18 at 11:48
  • @AydinK. : I tried this already. – plaidshirt May 02 '18 at 12:10
  • Please post the main class code? Also I hope the class is public as well ? – Tarun Lalwani May 02 '18 at 17:20
  • It has `@Test public void test() throws GeneralLeanFtException { }` method. It looks like as last example on this page: https://admhelp.microfocus.com/leanft/en/14.03/HelpCenter/Content/CodeSamples_Java/codeex_Mobile.htm – plaidshirt May 03 '18 at 07:58
  • 1
    java, when starting a `.jar`, uses a specific `main` signature: `public static void main(String[] args)` signature. Make sure you adapt to this signature – Adelin May 03 '18 at 13:00
  • @Adelin : Jar is generated, but got "A JNI error has occurred, please check your installation and try again" error message, when try to execute it. It is working when I use IDE for execution and doesn't use any arguments or parameter values. – plaidshirt May 03 '18 at 13:10
  • Kinda like this? https://stackoverflow.com/questions/22381202/a-jni-error-has-occurred-please-check-your-installation-and-try-again-in-eclips – Adelin May 03 '18 at 13:12
  • Yes, I checked this thread too, but wasn't there accepted solution/exact fix, just possible solutions. – plaidshirt May 03 '18 at 13:26
  • 1
    @plaidshirt - Ok may be, but that's a different issue unrelated to LeanFT. Most probably there's an issue with the way it's all packaged and configured. If you think it's worth it, try starting from scratch, with a simple `println` program, and then gradually add LeanFT and TestNG jars and then create the structure I proposed in my answer – Adelin May 04 '18 at 05:20

1 Answers1

1

It seems you have some kind of combination between test project (using LeanFT TestNG template), java app, who-knows-what-else app.

If you have a main method and still want to trigger TestNG tests, you need to use the TestNG class. For example

TestNG testNG = new TestNG();
testNG.setTestClasses(WebTestFactory.class);
testNG.run();

You can read more about this approach in the official docs or in this SO thread

If you don't have a main class, you should create one. (how else could a .jar file know what is the entry point?).

All in all, this error indicates there's a conflict between project type and project structure (content)


As per your recent comment: Could you please show me example/pattern, where to put main() method?

  1. You can create a new class file or even use LeanFTest
  2. Create main method.

    Whatever you do in the main method will drive your whole app. In your specific case (executing TestNG tests) you will need to do the followings, in your main method:

  3. Create a test ng instance (TestNG testNG = new TestNG();)

  4. Use this instance to prepare the test suite

    Pointing towards the SO thread above (again), it would mean something like:

    String xmlFileName = "testng.xml";
    List<XmlSuite> suite = (List <XmlSuite>)(new Parser(xmlFileName).parse());
    testNG.setXmlSuites(suite);
    
  5. Run the suite

    testNG.run();
    

After that, when you create your artifact, you point to the class that has the main method and double clicking the .jar (or executing it from command line) should start the test suite.

Adelin
  • 7,809
  • 5
  • 37
  • 65
  • Could you please show me example/pattern, where to put `main()` method? I used examples like this: https://admhelp.microfocus.com/leanft/en/14.03/HelpCenter/Content/HowTo/SetupLeanFT.htm to design tests. – plaidshirt May 03 '18 at 11:32
  • I created new class, but got same error message. I edited also question. – plaidshirt May 03 '18 at 12:58