Note that there are some explanatory texts on larger screens.

plurals
  1. POTestNG parallel tests failing
    primarykey
    data
    text
    <p>First let me put out the structure of my tests:</p> <ul> <li>There is <em>BaseTest</em>(Singleton) containing a <code>setUp()</code> method which runs <code>@BeforeSuite</code>. This setUp() method initializes <em>MyObject</em> which is declared as:</li> </ul> <p><code>protected static ThreadLocal&lt;MyObject&gt; myObject= new ThreadLocal&lt;MyObject&gt;();</code></p> <ul> <li><p>All other tests extend this <em>BaseTest</em>. e.g. Say <em>CustomerTest</em></p> <p>This <em>CustomerTest</em> have -</p> <ol> <li>A test with <code>@BeforeClass</code> tag - it gets the stored instance of MyObject. </li> <li>Other tests will use MyObject, perform some operation and do the tests</li> <li>A test with <code>@AfterClass</code> tag - does destroy the instance of MyObject</li> </ol></li> </ul> <p>So ideally, this setUp() method should run before any other test. And it runs <strong>only once</strong>.</p> <p>I am trying to run test cases parallely in TestNG framework. To achieve that, I have set the parallel attribute on the <code>suite</code> tag of testng.xml as</p> <p><code>&lt;suite name="Suite" parallel="classes" thread-count="5"&gt;</code></p> <p>Now, within the seconds after I fire the build, the build gets failed with all basic tests failed and others as skipped.</p> <p>Failed test are due to <code>java.lang.NullPointerException</code></p> <p>My understanding is, while setUp() method is being run on a thread, some other tests on different threads are trying to access the MyObject which isn't initialized yet. So is the failure. Is my understanding correct?</p> <p>If yes, what could be the possible solution to this? </p> <p>Can I do something like - let the thread run first in which setUp() is being run and till then don't let other threads invoke. And once the call to setUp() finishes/ returns, then allow other threads to invoke.</p> <p>(<strong>Note:</strong> My project uses Maven)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload