-1

I have created 5 test cases in JUnit 4 and I was wondering is it possible to build a collection of 100 objects for my 5th test case with Annotations (i.e. @BeforeTest in TestNG), or other techniques without conflicting with my previous test cases.

I've done some research on the different annotations in Junit 4 http://www.mkyong.com/unittest/junit-4-vs-testng-comparison/, and because the functionality of @BeforeTest is not available in JUnit 4 but is completely suited to what I want, what other options are there?

Thanks!

classicjonesynz
  • 4,012
  • 5
  • 38
  • 78
  • Why not try it out, just do 10 objects 1st.. should b ok – Caffeinated Apr 01 '12 at 01:05
  • 1
    I've been asked to test a test case that will loop through 100 objects in under 100 ms.. so these objects must be created before the test case does its thing. – classicjonesynz Apr 01 '12 at 01:06
  • possible duplicate of [JUnit: @Before only for some test methods?](http://stackoverflow.com/questions/1548462/junit-before-only-for-some-test-methods) – derekerdmann Apr 01 '12 at 01:08
  • @Adel my question is not referring to how I would create the objects, my question is referring to when should I create the objects in order to not effect the initial timeout parameter on my test5. – classicjonesynz Apr 01 '12 at 01:23

1 Answers1

0

shouldn't be any problem. the before test is used just for that test case. ditto for the after test.

Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
  • BeforeTest/AfterTest does not exist in JUnit4 and the functionality of 'Before' is very limited and does not work on testcases but solely on functions of a class ('Before' public void test5() {} will return a error), Any other suggestions will be good thanks :) – classicjonesynz Apr 01 '12 at 01:29
  • As far I know doesn't seem like there is any other solution than what you have suggested.. so I've decided to separate my collections and initialise one with 100 objects and keep the other empty with @Before public void setUp. thanks Ray – classicjonesynz Apr 01 '12 at 01:45
  • before and after are for the test case not the test. they are called before and after each test in the test case. – Ray Tayek Apr 01 '12 at 01:46
  • put the test that needs 100 objects in a separate test case. – Ray Tayek Apr 01 '12 at 01:47
  • Yeah I thought about that, but when I asked the question I was wondering if there any other options to run something before a specific test case and not all test cases. – classicjonesynz Apr 01 '12 at 02:35