I am new to Junit. I have a class with four methods. I am creating a test class with test cases. Can I have a test case that uses more than one methods of testing class or there should one test case per one method. What is good practice ?
Can I have a test case that uses more than one method of the tested class
Obviously yes, how will you otherwise test methods which need a specific initialization before? For example
fooCalculator = new FooCalculator(someParameters); fooCalculator.SetOption1(valueForOption1); fooCalculator.SetOption2(valueForOption2); result = fooCalculator.Calc(); Assert.AreEqual(expectedResultForTheseOptions,result);
If, however, your question is "Can I have a test case that tests more than one method", then the answer is "you should avoid that", because that will typically result in too large tests. See this former question for a detailed explanation.