c# - Unit Tests from multiple test classes appear to be interleaved -


i have tests in 2 separate classes within mstest project, each class (i think) set , each class runs fine when run whole project's tests, fail.

my 2 classes both involve setting external data each class designed make sure in known state before starting (and wipe after finishing). have though mstest might run methods in test class in parallel(?), run each class in sequence... incorrect assumption?

edit: came across question (how mstest determine order in run test methods?) seems suggest vs may interleave tests multiple classes in (seemingly not actually) random order i.e. not run tests in classa before starting in classb. problematic in case because if order tests within class, mstest might still run methods multiple classes conflict?

important note

mstest doesn't guarantee order of execution , order can different between runs. if need rely on order you'll need created ordered test, vs premium/enterprise feature unless you're on visual studio 2015 update 2, brought them pro.

test execution can interleave, bounce , kinds of crazy things. though on versions of mstest tends run in alphabetical order of full namespace of test, e.g.: my.namespace.class.method.

when using data driven tests it's weirder order of data coming datasource acts additional randomizer.

do not rely on order it's better use testinitialize , run code before each test executes rely on [class|assembly]initialize setup data in ways incompatible between different tests.

visual studio 2015 , earlier.

mstest can execute tests in parallel using legacy test runner , when specifying parallelism in testsettings file. in legacy runner tests executed on 5 threads. legacy test runner not constrain tests in way. run tests in parallel if can , there no specific order or protection. can see in screenshot below:

enter image description here

unless testsettings explicitly mention parallism, tests run sequentially, no specific order. suspect use il order of compiled assembly or alphabetical order. order in source file not used.

in visual studio 2015 update 1 , later

visual studio 2015 update 1 introduced option run tests in parallel in new test runner. new test runner uses different approach , parallellize tests per container. c# means means tests in 1 assembly executed sequentially while tests in separate assemblies can executed in parallel.

it assumed integration tests , ui tests kept in own separate solution , when enable parallel option have solution containing unit tests.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -