Giter Site home page Giter Site logo

parallel="classes" is not forcing test methods from the same testClass to be run in the same thread as it is suposed to (I guess) about testng HOT 10 CLOSED

romlom avatar romlom commented on August 15, 2024
parallel="classes" is not forcing test methods from the same testClass to be run in the same thread as it is suposed to (I guess)

from testng.

Comments (10)

lrivera avatar lrivera commented on August 15, 2024

Reproduced this error, i'm working on this.

from testng.

JIGD avatar JIGD commented on August 15, 2024

found a fix, will be posting it soon :)

from testng.

gillius avatar gillius commented on August 15, 2024

Thanks for finding this issue and posting the workaround. I just spent an hour or two trying to figure out why my test methods in the same class were running in parallel. Adding an empty @Test method resolves this issue. I tested TestNG 6.8 and 6.8.8 and both had this problem, so either the issue wasn't fixed or it has regressed.

from testng.

sergejjkim avatar sergejjkim commented on August 15, 2024

Any chance this could be fixed?

from testng.

kostia-hospodarysko avatar kostia-hospodarysko commented on August 15, 2024

This works as expected:

Here are my (little bit modified) classes:

package com.example;
public class A {
    @org.testng.annotations.Test
    public void someMethodA1() {
        PrintThread.message("in A");
    }
}

package com.example;
public class B extends A {
    @org.testng.annotations.Test
    public void someMethodB1 () {
        PrintThread.message("in B");
    }
}

package com.example;
public class C extends B {
    //@org.testng.annotations.Test
    public void veryImportant() {
        PrintThread.message("in c");
    }
}

package com.example;
public class PrintThread {
    public static void message(String s) {
        System.out.println("START["+Thread.currentThread().getId()+"]: " + s);
        synchronized (s) {
            try { s.wait(1000); }
            catch (InterruptedException e) {}
        }
        System.out.println("END["+Thread.currentThread().getId()+"]: " + s);
    }
}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Some Suite" >
    <test name="Some tests" parallel="classes" thread-count="3">
        <packages>
            <package name="com.example"/>
        </packages>
    </test>
</suite>

The output when @test in C is commented:

START[11]: in A
START[12]: in A
START[13]: in A
END[12]: in A
END[11]: in A
END[13]: in A
START[12]: in B
START[11]: in B
END[12]: in B
END[11]: in B

So it is seen that:

  • two tests were executed for class B in its own thread
  • two tests were executed for class C in its own thread
  • one test was executed for class A

All is as expected.

The output when @test in C is uncommented:

START[14]: in A
START[16]: in A
START[15]: in A
END[15]: in A
END[14]: in A
END[16]: in A
START[15]: in B
START[16]: in B
END[16]: in B
END[15]: in B
START[16]: in c
END[16]: in c

So it is seen that:

  • three tests were executed for class C in its own thread (16)
  • two tests were executed for class B in its own thread (15)
  • one test was executed for class A (14)

All is as expected.

from testng.

sergejjkim avatar sergejjkim commented on August 15, 2024

@khospodarysko thanks for an example.
However it doesn't contain an abstract class.
I have two classes and a suite:

public abstract class A {
    @Test
    public void test1() {
        message("test1");
    }

    @Test
    public void test2() {
        message("test1");
    }

    public static void message(String s) {
        System.out.println("START["+Thread.currentThread().getId()+"]: " + s);
        synchronized (s) {
            try { s.wait(1000); }
            catch (InterruptedException e) {}
        }
        System.out.println("END["+Thread.currentThread().getId()+"]: " + s);
    }
}

public class B extends A {}

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Some Suite" parallel="classes" thread-count="8">
    <test name="Some tests" >
        <classes>
            <class name="B"/>
        </classes>
    </test>
</suite>

what i get is two test running in separate threads:
START[12]: test1
START[13]: test1
END[13]: test1
END[12]: test1
what i expect to get is two tests running in the same thread cause they belong to a same class.

from testng.

kostia-hospodarysko avatar kostia-hospodarysko commented on August 15, 2024

Hey, @sergejjkim

Your are right, I forgot about abstract.

So the one thing I did is I made classes A and B as abstract and get such output:

START[12]: in A
END[12]: in A
START[12]: in B
END[12]: in B
START[12]: in c
END[12]: in c

Is that what you are expecting?

from testng.

sergejjkim avatar sergejjkim commented on August 15, 2024

@khospodarysko
ok so I've made A and B abstract in your example with @test in C commented and got
START[13]: in B
START[12]: in A
END[12]: in A
END[13]: in B
which is basically not what I'd expect to see. Also it's more about having 2 classes with 2+ methods in the abstract one.

from testng.

kostia-hospodarysko avatar kostia-hospodarysko commented on August 15, 2024

@sergejjkim Got it!

Similar Eclipse-related issues that I've found are:

I'd say this case is rather edge-case. If one of subclasses has one @test method all is OK.

from testng.

thibaut-sticky avatar thibaut-sticky commented on August 15, 2024

Any update or idea to fix this issue? We use a lot of abstract class tests to override just some small part of them with sub classes to change a behavior. These subclasses have no test inside, but added an empty one made these tests ran in a single thread as expected.

from testng.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.