[英]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: 我正在尝试使用JUnit测试一个类,当我尝试运行测试时,总是会收到此错误:
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.
我想要实现的一切就是可以正确使用JUnit。 So what am I missing here?
那我在这里想念什么? Do I need to change the manifest or something else?
我是否需要更改清单或其他内容?
我想您应该使用AndroidTestCase扩展您的Test类,请在Android文档中查看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.