question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestNG cannot find JUnit method names from Spock

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:13

github_iconTop GitHub Comments

3reactions
FibreFoXcommented, Jun 3, 2016

@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.

0reactions
rumatoestcommented, Jun 3, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Eclipse cannot find groovy class for Spock/Junit test
To do this, in the Package Explorer window, right click on the Project name, select "Build Path" from the menu, then select "Configure...
Read more >
Problems using Spock and TestNG together - Google Groups
I want to be able to keep most existing tests, and use Spock/JUnit in parallel. TestNG has an option for that: junit="true" on...
Read more >
TestNG | IntelliJ IDEA Documentation - JetBrains
To quickly navigate to a file, press Ctrl+Shift+N and enter its name. ... In the tool window that opens, type testNG in the...
Read more >
Stubbing and Mocking in Java with the Spock Testing ...
Learn how to create true Java unit tests by mocking all external dependencies in your unit tests with the Spock testing framework.
Read more >
Maven Surefire Plugin – surefire:test - Apache Maven
1 and JUnit 4.12, the @Category annotation type is automatically inherited from superclasses, see @java.lang.annotation.Inherited . Make sure ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found