Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotation Type Expected

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());
    }
}
like image 260
jensengar Avatar asked Apr 17 '13 14:04

jensengar


People also ask

What is@ test annotation?

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.

Which annotation is used to classify method as test method in JUnit testing?

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.

What does@ test mean in JUnit?

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.


2 Answers

The import should be

import org.junit.Test;

and not

import junit.framework.Test;
like image 155
JB Nizet Avatar answered Sep 20 '22 08:09

JB Nizet


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.

like image 37
Anil Bhaskar Avatar answered Sep 19 '22 08:09

Anil Bhaskar