junit4 - Selenium WebDriver -Tests that use other tests -


as example, have:

@test public void login(*code ommitted*){ 

that tests logging site.

then want other tests start logging in, i've got:

@test public void senduserinvite(){ login(); *other code omitted* } 

something intuitively telling me bad practise, @ same time if login test need to, why not re-use in way? can clarify this. after while end doing several tests @ start of test because pre-conditions in order carry out particular test.

if you're using testng, can use @beforeclass, @beforesuite, @beforetest, @beforemethod etc. in order launch preconditions on step before @test method

e.g. have 2 tests in xml:

<suite name="suite0" verbose="1" >   <test name="name0" >     <classes>        <class name="test0" />     </classes>   </test>    <test name="name1">     <classes>       <class name="test1"/>     </classes>   </test> </suite> 

let's assume test0 , test1 both extend class basetest

then in basetest:

public class basetest {      @beforetest     public void login() {          // smth w/ login     }  } 

so, when suite launched, login method invoked. note @beforetest work every test suite, not every method @test, confuses.

upd

if you're using junit, can use @before, , method run before every @test in class. say, same @beforemethod in testng

@before public void pre() {      // login here }  @test public void testa() {      // prints }  @test public void testb() {      // prints b }  @after public void end() {      // logout } 

order of execution:

login

a

logout

login

b

logout


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -