Testng: TestNG cannot find JUnit method names from Spock

Created on 1 Apr 2014  ·  13Comments  ·  Source: cbeust/testng

The Spock framework creates JUnit tests. These should be able to be run via TestNG. However, in the org.testng.junit.JUnit4TestMethod class there is this code:

    private static Method getMethod(Description desc) {
        Class<?> c = desc.getTestClass();
        String method = desc.getMethodName();
        try {
            return c.getMethod(method);
        } catch (Throwable t) {
            Utils.log("JUnit4TestMethod", 2,
                    "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage());
            return null;
        }
    }

Since the passed in description has the text of the Spock test (something like: "This is my spock test") and Spock mangles the test names, the simple "c.getMethod(method)" call fails. If this is fixed, then TestNG should be able to run Spock (JUnit) tests as well.

junit

Most helpful comment

@rumatoest Instead of complaining you could spend your free time to debug/bugfix this. I'm sick of people thinking about usable tools/frameworks as always being baked by a huge company. TestNG is, as stated by @juherr, a spare-time project.

As I'm already wanted to get in touch with Spock (always eager to learn new stuff), I might take a look into this the next time.

All 13 comments

I wonder why TestNG is trying to get the Method for the test. This will cause troubles with quite a few testing frameworks implementing a JUnit runner.

+1

+1

+1

+1

+1

+1

This ticket is now 2+ years old. It still doesn't even have anyone (EVER) assigned! What a complete joke. If anyone is even considering use of TestNG you should be aware of the extremely poor support to expect. I only wish all of our tests were in JUnit...

We are supporting testng during our free time and we fixed other most important issues.

But the project is open, why not trying to fix it by yourself ? We'll love to help you to make a pull-request.

At the end, and as you said, JUnit is a solution too (and a good project).

@blackduck-joe I had a look on the issue and I've no idea how to fix it.

But your need is clearer in your SO thead, and if I understand it well you want to run 2 kind of tests (spock/junit and testng).
Then, if you are using maven, you should have a look on https://groups.google.com/forum/#!topic/spockframework/-iys4ARQrxk and/or Running TestNG and JUnit Tests

Conceptually necessity of adding junit into my current project will lead me to use only junit in next projects.

@rumatoest Instead of complaining you could spend your free time to debug/bugfix this. I'm sick of people thinking about usable tools/frameworks as always being baked by a huge company. TestNG is, as stated by @juherr, a spare-time project.

As I'm already wanted to get in touch with Spock (always eager to learn new stuff), I might take a look into this the next time.

Was this page helpful?
0 / 5 - 0 ratings