I just created this unit test, and I get a red squiggly under @Test
that says "Annotation Type Expected". What does this mean?
package com.sample.bank.account;
import junit.framework.Test;
import static org.junit.Assert.*;
public class LoanTest {
@Test
public void testAppliyPaymentSubtractsCorrectAmount()
{
Loan loan = new Loan("test subtract", 1000);
loan.applyPayment(100);
assertEquals(900, loan.getBalance());
}
}
The Test annotation tells JUnit that the public void method to which it is attached can be run as a test case. To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method. Any exceptions thrown by the test will be reported by JUnit as a failure.
A JUnit test is a method contained in a class which is only used for testing. This is called a Test class. To define that a certain method is a test method, annotate it with the @Test annotation.
JUnit provides an annotation called @Test, which tells the JUnit that the public void method in which it is used can run as a test case. A test fixture is a context where a test case runs. To execute multiple tests in a specified order, it can be done by combining all the tests in one place.
The import should be
import org.junit.Test;
and not
import junit.framework.Test;
The import should be
import org.junit.Test;
If you are using jUnit 4.
If you are using upto jUnit 3.8.
import junit.framework.Test;
should work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With