Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How can fail a test with TESTNG if my code throws an exception?

 
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

How can assert and where so if I receive one exception my test to be failed?





My stacktrace is:



In my case the test is passes in NetBeans.

Thanks in advance

 
Ranch Hand
Posts: 261
15
Android Angular Framework Spring AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Dana:
I think what you are asking is: 'given this code fails with an exception, how can I assure that the test itself fails?'  That's a great thing to do, IMHO.  I think there are two ways.
1) don't catch the exception; instead declare your AdaugProdusLaCos() method with a "throws Exception" clause.
2) in your catch block, if you want to be explicit about the failure, you can add "Assert.fail(ex.getMessage());", or whatever else you want to say.

This second one will let you be very exact.  But you will have to import the Assert class.  That's under org.testng.Assert.  Here's a page that includes this info.

http://toolsqa.com/selenium-webdriver/testng-reporters-asserts/

Good luck, and thanks for indirectly introducing me to this. In the past I had worked with HtmlTest, HttpTest and even one I wrote myself a long time ago.  This "testng" or "Selenium" looks quite convenient and very similar to Junit.
 
Dana Ucaed
Ranch Hand
Posts: 459
6
Netbeans IDE Oracle Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I discovered the one annotation

@BeforeMethod(alwaysRun = true) who do what do I want.

 
What's wrong? Where are you going? Stop! Read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic