@AfterClass method don't finish the testcase

18
June 13, 2019, at 3:40 PM

I'm testing my databse. I'm using the @BeforeClass method to delete everything in my databasetable then inserting some data.

Then I run my tests.

Then I want to use my @AfterClass method to basicly do exactly the same as the @BeforeClass method does.

Everything works but when I add the @Afterclass method my test stucks on the last junit test for ever.

    @AfterClass
    public static void stop() {
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        Query query = session.createQuery("DELETE FROM DB");
        query.executeUpdate();
        session.getTransaction().commit();
        session.close();
        Session session3 = sessionFactory.openSession();
        session3.beginTransaction();
        Query query3 = session3.createSQLQuery("ALTER TABLE db AUTO_INCREMENT=1;");
        query3.executeUpdate();
        session3.getTransaction().commit();
        session3.close();
        Session session2 = sessionFactory.openSession();
        session2.beginTransaction();
            DB db = new DB();
            db.setTitle("Hallo Titel");
            session2.save(db);
        session2.getTransaction().commit();
        session2.close();
    }

I know for sure that the @AfterClass method is starting because the last print in the console is this:

Hibernate: delete from db Hibernate: ALTER TABLE db AUTO_INCREMENT=1;

But for some reason the method does not finish. In the Junit Tab it stucks on the last test.

When I remove the @AfterClass Method everything terminates perfectly.

READ ALSO
Android.graphics.rect - always null

Android.graphics.rect - always null

I want to write some tests for my Android project - and I‘m trying to instantiate a Rect()-Object in a JUnit test - but I’m always getting a null instead of the objectHere some examples:

33
Issue with parsing LocalDate to Date in Java [duplicate]

Issue with parsing LocalDate to Date in Java [duplicate]

This question already has an answer here:

44
Nonblocking Java Async Processing - how to constrain memory usage?

Nonblocking Java Async Processing - how to constrain memory usage?

I'm coming back to Java after a few years away, and have been excited to see the introduction of non-blocking async support in the new javanet

24
Filter log by conversion pattern [%t]

Filter log by conversion pattern [%t]

I am using the log4j2 version 211

42