zerocode icon indicating copy to clipboard operation
zerocode copied to clipboard

Running SetUp And TearDown code when testing Kafka using the ZeroCode

Open shafeeknaidoo opened this issue 6 years ago • 3 comments

Hi As the title suggests, I am unable to Run Setup and Teardown methods when Testing Kafka.

I use @Before Annotations on my "setup" Methods but nothing seems to work. My code as below

@TargetEnv("Kafka/KafkaTestServer.properties")
@RunWith(ZeroCodeUnitRunner.class)
public class TestClass{


    @Before
    public void before() {
        //before code here NB actual code omitted
    }

    @Test
    @JsonTestCase("path/to/testcase.json")
    public void TestOne() {
    }
}

When i remove '@JsonTestCase' annotation it works.

Any help would be appreciated

shafeeknaidoo avatar Sep 17 '19 14:09 shafeeknaidoo

Hi @shafeeknaidoo,

@Before and @After are usually used for Unit testing, so these methods are executed before/after each test case.

As Zerocode is designed for Integration testing, the before/after methods should be run only once for the entire set of test cases/test suite.

Hence in Zerocode, this functionality is implemented using '@BeforeClass' and '@AfterClass' annotations for your needs.

In short, if you replace '@Before' annnotation with '@BeforeClass', this will solve your problem.

officiallysameer avatar Sep 17 '19 14:09 officiallysameer

Hi @shafeeknaidoo,

@Before and @After are usually used for Unit testing, so these methods are executed before/after each test case.

As Zerocode is designed for Integration testing, the before/after methods should be run only once for the entire set of test cases/test suite.

Hence in Zerocode, this functionality is implemented using '@BeforeClass' and '@afterclass' annotations for your needs.

In short, if you replace '@before' annnotation with '@BeforeClass', this will solve your problem.

As im Testing Kafka, I need the topics i created to be emptied out before each test, also i have some KTables that i need to populate, It smy understanding that beforeClass and AfterClass annotations will only run before and after all the tests get run?

shafeeknaidoo avatar Sep 17 '19 14:09 shafeeknaidoo

Hi @shafeeknaidoo,

Can you join our slack channel.\https://join.slack.com/t/zerocode-workspace/shared_invite/enQtNzYxMDAwNTQ3MjY1LTA2YmJjODJhNzQ4ZjBiYTQwZDBmZmNkNmExYjA3ZDk2OGFiZWFmNWJlNGRkOTdiMDQ4ZmQyNzcyNzVjNWQ4ODQ

We can decide a time to meet on slack and discuss it there

officiallysameer avatar Sep 20 '19 14:09 officiallysameer