parallel="methods" not working sometimes

196 views
Skip to first unread message

Lakshay Chhikara

unread,
Jun 20, 2016, 10:23:01 AM6/20/16
to testng-users
I am using eclipse with testng plugin.

I am having a problem that i am not able to understand that when i run the test, sometimes i get 3 threads executing in parallel while sometimes only 1 thread (i.e. it becomes sequential).

Anything i might be missing here?

my testng.xml :

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

My TestNG.java :

package com.example.testng;

import org.testng.annotations.Test;

public class TestNG {
  @Test
  public void test1() {
 System.out.println("Start of test 1");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 1");
 }
  }
  
  @Test
  public void test2() {
 System.out.println("Start of test 2");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 2");
 }
  }
  
  @Test
  public void test3() {
 System.out.println("Start of test 3");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 3");
 }
  }
  
  @Test
  public void test4() {
 System.out.println("Start of test 4");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 4");
 }
  }
  
  @Test
  public void test5() {
 System.out.println("Start of test 5");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 5");
 }
  }
  
  @Test
  public void test6() {
 System.out.println("Start of test 6");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 6");
 }
  }
  
  @Test
  public void test7() {
 System.out.println("Start of test 7");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 7");
 }
  }
  
  @Test
  public void test8() {
 System.out.println("Start of test 8");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 8");
 }
  }
  
  @Test
  public void test9() {
 System.out.println("Start of test 9");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 9");
 }
  }
  
  @Test
  public void test10() {
 System.out.println("Start of test 10");
 try {
 Thread.sleep(10000);
 } catch (InterruptedException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 } finally {
 System.out.println("End of test 10");
 }
  }
}


⇜Krishnan Mahadevan⇝

unread,
Jun 20, 2016, 10:29:33 AM6/20/16
to testng...@googlegroups.com
I didnt quite understand what is your question here.


>>>>I am having a problem that i am not able to understand that when i run the test, sometimes i get 3 threads executing in parallel while sometimes only 1 thread (i.e. it becomes sequential).

How are you stating this ? Have you tried adding a System.out.println("Thread ID: " + Thread.currentThread.getId()) and see what you get ? This is the only reliable way of figuring out if you are indeed spinning off threads in parallel or sequence.



Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

Lakshay Chhikara

unread,
Jun 21, 2016, 1:43:06 AM6/21/16
to testng-users
Hey Krishnan, thanks for the fast reply and sorry for my late one.

I figured it out just a few minutes ago. I was accidently running the TestNG.java file sometimes which resulted in the sequential execution of the tests and when unknowingly ran testng.xml the tests ran parallely since i had configured their parallel run in testng.xml file.

Silly mistake ;P on my part.
Reply all
Reply to author
Forward
0 new messages