Error Symbol Method Asserttrueboolean
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the
Cannot Find Symbol @test
company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions package org.junit does not exist maven Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million
Java: Package Org.junit Does Not Exist
programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Junit method not found up vote 14 down vote favorite 1 I'm trying to build a sample test class using cannot resolve method assertequals junit framework. I've downloaded junit4.9b3. When I try to complie my test class I get the following error:- javac -cp ".;C:\Documents and Settings\user\Desktop\junit\junit4.9b3\junit-4.9b3.jar" TestSubscription.java TestSubscription.java:10: cannot find symbol symbol : method assertTrue(boolean) location: class TestSubscription assertTrue(s.pricePerMonth()==100.0); ^ TestSubscription.java:17: cannot find symbol symbol : method assertTrue(boolean) location: class TestSubscription assertTrue(s.pricePerMonth()==66.67); ^ 2 errors Looks like assertTrue is not available but the junit javadoc mentions this method. I'm using the import as follows import org.junit.*; import package junit.framework does not exist org.junit.Assert.*; Any ideas? java junit share|improve this question edited Feb 14 '13 at 7:00 Siddharth 5,44464684 asked Jul 21 '11 at 7:27 Ankur 2,953134257 You have marked the incorrect answer as "correct". –Siddharth Feb 14 '13 at 5:11 add a comment| 2 Answers 2 active oldest votes up vote 35 down vote accepted You've imported the types, but not used a static import to make the members available without qualification. If you use: import static org.junit.Assert.*; then that should statically import all the static methods in the Assert class, so you can write assertTrue instead of Assert.assertTrue. Note that presumably Assert itself has nested types, otherwise I'd have expected your "normal" import to fail. share|improve this answer edited Feb 14 '13 at 6:42 answered Jul 21 '11 at 7:30 Jon Skeet 900k48765347460 thanks. Fixed the code and its working. The right way is import static org.junit.Assert.*;. –Ankur Jul 21 '11 at 7:49 This is the incorrect answer, import static org.junit.Assert.*; is the correct way to do it. –Siddharth Feb 14 '13 at 5:10 @Siddharth: Fixed, thanks. –Jon Skeet Feb 14 '13 at 6:42 reverted the downvote and upvote. –Siddharth Feb 14 '13 at 6:57 add a comment| up vote 7 down vote You have to do a
This Site Careers Other all forums Forum: Testing Junit test: cannot
Cannot Resolve Symbol Assert
find test Method although that it is already org.junit maven defined in the test class ashley Jug Ranch Hand Posts: 60
Junit Assertnotequals
posted 5 years ago Hello, I have never used junit before and have a question regarding junit test: I have the http://stackoverflow.com/questions/6772647/junit-method-not-found following method in my class SQLUtils: package com.training.perso import java.sql.Connection; public class SQLUtils { public boolean queryNamePassword(String userName,String passwrd)throws Exception{ //locate jdbc jar the driver Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager .getConnection("jdbc:mysql://:3306/mydb","random", "22222"); StringBuffer sb = new StringBuffer("select name,password from guesttbl where name https://coderanch.com/t/551437/Testing/Junit-test-find-test-Method =" +"'"+userName+"'" +"and password ="+"'" +passwrd+"'"); PreparedStatement statement = con.prepareStatement(sb.toString()); ResultSet result = statement.executeQuery(); logger.info(sb.toString()); while (result.next()){ logger.info("name "+result.getString("name")); logger.info("password "+result.getString("password")); return true; } return false; } } I have created a unit test class in a new package for the method above: import com.training.perso.SQLUtils; import junit.framework.TestCase; public class Junit_TestSQL extends TestCase { public void TestLogIn() throws Exception{ SQLUtils sql = new SQLUtils(); assertTrue(sql.queryNamePassword("random", "password")); } } However when i run the unit test i get the following error message: junit.framework.AssertionFailedError: No tests found in com.training.JUnittest.Junit_TestSQL at junit.framework.Assert.fail(Assert.java:47) at junit.framework.TestSuite$1.runTest(TestSuite.java:263) at junit.framework.TestCase.runBare(TestCase.java:127) at junit.framework.TestResult$1.protect(TestResult.java:106) at junit.framework.TestResult.runProtected(TestResult.java:124) at junit.framework.TestResult.run(TestResult.java:109) at junit.framework.TestCase.run(TestCase.java:118) at junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Can anybody advice me how i c
Unknown argument: -Init Buildfile: C:eclipseworkspacePersistanceuild.xml -Init: [echo] Build time: March 31 2004 1441 -Prep: [delete] Deleting directory C:eclipseworkspacePersistancein [delete] Deleting directory C:eclipseworkspacePersistancedist [mkdir] Created dir: C:eclipseworkspacePersistancein [mkdir] Created dir: C:eclipseworkspacePersistancedist [mkdir] Created dir: C:eclipseworkspacePersistancedistlib Compile: [javac] Compiling 12 source files to C:eclipseworkspacePersistancein [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceAllTests.java:9: package junit.framework does not exist [javac] import junit.framework.Test; [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceAllTests.java:10: package junit.framework does not exist [javac] import junit.framework.TestSuite; [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceAllTests.java:23: cannot resolve symbol [javac] symbol : class Test [javac] location: class org.eclipseguide.persistence.AllTests [javac] public static Test suite() [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceFilePersistenceServicesTest.java:13: package junit.framework does not exist [javac] import junit.framework.TestCase; [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceFilePersistenceServicesTest.java:23: cannot resolve symbol [javac] symbol : class TestCase [javac] location: class org.eclipseguide.persistence.FilePersistenceServicesTest [javac] public class FilePersistenceServicesTest extends TestCase [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceObjectManagerTest.java:11: package junit.framework does not exist [javac] import junit.framework.TestCase; [javac] ^ [javac] C:eclipseworkspacePersistancesrcorgeclipseguidepersistenceObjectManagerTest.java:21: cannot resolve symbol [javac] symbol : class TestCase [javac] location: class org.eclipseguide.persistence.ObjectManagerTest [javac] public class ObjectManagerTest extends TestCase [javac] ^ [javac] C