Fongo TestNG Delete before method

95 Views Asked by At

reading at fongo documentation i found that it supports the @Rule annotation to delete the contents of the DB before executing a test.

i want to achieve the same thing using TestNG but i can't find the correct way to do this, i tried calling fongo.dropDatabase(dbName) but it doesn't work as expected, if i call this method it seems that DB is droped but no new instance is created when inserting a new document.

also tried to delete and instance again fongo, but also no results. its the same i can create or update documents but if i try to fetch a document there will be no results.

to delete contents of fongo db i'm using @BeforeMethod annotation and there call to dropDatabase().

how should i delete db before every test?

1

There are 1 best solutions below

0
juherr On

The easiest way is to call the JUnit rule by hand in @BeforeMethod and @AfterMethod: FongoRule#before() and FongoRule#after(). A better solution would use a TestNG listener.

But you should ask for a TestNG support in fongo: https://github.com/fakemongo/fongo/issues