Raggedtoad
Raggedtoad

Reputation: 521

ABAP Unit Testing - Why is my setup method being called twice?

I have a local class definition and implementation on a particular ABAP object for testing. I am implementing the setup and teardown methods as part of the test. Now, when I right-click on the class in transaction SE80, and click Unit Test, it runs as expected, except that it appears my setup method is being called twice, which results in failures because duplicate data is being created in the database. Has anyone seen anything like this before?

Upvotes: 3

Views: 1444

Answers (2)

Raggedtoad
Raggedtoad

Reputation: 521

I was using SETUP and TEARDOWN fixtures where I should have been using CLASS_SETUP and CLASS_TEARDOWN fixtures.

The regular SETUP and TEARDOWN fixtures are called before EACH test method, whereas the CLASS_SETUP and CLASS_TEARDOWN fixtures are only called respectively once before running all the test methods in the class and once afterwards.

For more information, read the ABAP documentation about test classes.

Upvotes: 5

Damir
Damir

Reputation: 56

The Methods SETUP and TEARDOWN are called every Time before/after an Testmethod is executed. Maybe you have implemented two Test-Methods, so you got duplicated data.

With the class-methods class_setup and class_teardown you can define Test-Fixture's which are executed before/after every test of the class.

More Information on: SAP Help

Upvotes: 1

Related Questions