86565

How to implemet singleThreaded=true in TestNG

Question:

In TestNG i am trying to undertand the use of singleThreaded=true attibute of @Test Annotation .I already referred <a href="http://testng.org/doc/documentation-main.html" rel="nofollow">http://testng.org/doc/documentation-main.html</a> and <a href="http://beust.com/weblog2/archives/000407.html" rel="nofollow">http://beust.com/weblog2/archives/000407.html</a> but didn't got much help .

My Question : Why do we need to execute method on single thread. Running on multiple thread can save out time.

Note : In the example given at <a href="http://beust.com/weblog2/archives/000407.html" rel="nofollow">http://beust.com/weblog2/archives/000407.html</a>

He said :: "the two test methods testf1() and testf2() test the methods A#f1 and A#f2 respectively, but when you ask TestNG to run these tests in parallel mode, <strong>these two methods will be invoked from different threads, and if they don't properly synchronize with each other, you will most likely end up in a corrupt state.</strong>

Can anyone explain with code the above example

Answer1:

As is explained here <a href="http://beust.com/weblog2/archives/000407.html" rel="nofollow">http://beust.com/weblog2/archives/000407.html</a> <strong>...if the classes you are testing are not multithread-safe...</strong>

So your tests can run in parallel, but if you are testing classes which are not thread safe things can break.

In example one test calls a.f1() and second one calls a.f2(). If these methods uses some shared resources in object this.a = new A() and depends on each other <strong>you will most likely end up in a corrupt state</strong> with object this.a.

Recommend

  • c# closing sqlconnection and sqldatareader or not?
  • Can a C compiler add padding before the first element in a structure?
  • C# linq to sql - selecting tables dynamically
  • I don't get the e-mail using this code. What is the problem?
  • CRM Dynamics How to set short list - long list relationship
  • Is it possible to use LinkShare signatures in an iOS Smart Banner?
  • LIBSODIUM decrypt data inside mysql query like did with AES_DECRYPT
  • How to get Attachment value from “$File” Item? using C# (Lotus Notes)
  • How to create 2 svg's on one page?
  • Window-select multiple artists and drag them on canvas
  • How to detect beginning of line, or: “The name 'getCharPositionInLine' does not exist in t
  • How to send binary with spring boot websocket?
  • Ruby on Rails - Settting up Reviews functionality
  • Train two models concurrently
  • how to reload page after uploading images
  • Working with codeception and laravel
  • Can I switch the 'connected' user within an sql script that is sourced by mysql?
  • jqGrid Filter Toolbar and Date and Select filters
  • Gitlab: copy project to other git lab repository
  • iOS App crash issue `[UIWindow warpPoint:]`
  • How to search for a method or variable name within android project?
  • Smarter Removing Unnecessary WhiteSpace CSV
  • MayAVI install on Python 3.6 [duplicate]
  • Signed Java web start application with Glassfish 4.1 and Java7
  • Arraylist of strings into one comma separated string
  • Autocomplete source from project settings
  • How to use AJAX to upload large CSV file? [closed]
  • flex tree gets chopped even after using scroll bar
  • Query takes almost two seconds but matches only two rows - why isn't the index helping?
  • How to make Rss News Reader application in android …? [closed]
  • How to check if a database and tables exist in sql server in a vb .net project?
  • Typeahead.js does give me suggestions but doesn't select them
  • How to specify generic type when the type is only known at runtime?
  • How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app
  • How to handle div that is created dynamically in a table
  • Google App Engine backend servlet not responding
  • Make checkout phone field optional for specific countries in WooCommerce
  • Excel VBA : conditional formatting of sheet1 cells from sheet2 values in excel 2007
  • Android Library Projects on Windows and Mac