简体   繁体   中英

java.lang.NoClassDefFoundError: android/app/Activity error when testing with JUnit in Eclipse

I'm trying to test a class with JUnit and I always get this error when i try to run the test:

java.lang.NoClassDefFoundError: android/app/Activity

This is my test class:

package sol.travel.trippin;

import static org.junit.Assert.*;

import org.junit.*;
import sol.travel.trippin.LogIn;

public class LogInTest {

@Test
public void testWeakEmailAndPasswordValidation() {
    assertEquals("Vil fa true her tvi baedi eru uppfyllt", true, LogIn.weakEmailAndPasswordValidation("asdf@hi.is", 3));
    assertEquals("Vil fa false her tvi password lengd er 0", false, LogIn.weakEmailAndPasswordValidation("asdf@hi.is", 0));
    assertEquals("Vil fa false her tvi email inniheldur ekki .", false, LogIn.weakEmailAndPasswordValidation("asdf@is", 3));
    assertEquals("Vil fa false her tvi email inniheldur ekki @", false, LogIn.weakEmailAndPasswordValidation("sadfhi.is", 3));
}

and this is the function I'm trying to test:

package sol.travel.trippin;

public class LogIn extends HideKeyboard {

    public static boolean weakEmailAndPasswordValidation(String mail, int pwLength){
        if(mail.contains("@")&& mail.contains(".") && pwLength !=0 )
        {
                return true;
        }
        else
        {
            return false;
        }
    }
}

I know these functions are not good and comments regarding that are unnecessary. All I'm trying to achieve is that I can use JUnit properly. So what am I missing here? Do I need to change the manifest or something else?

我想您应该使用AndroidTestCase扩展您的Test类,请在Android文档中查看

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM