wood burning stoves 2.0*
The moose likes Testing and the fly likes Junit test: cannot find   test Method although that it is already defined in the test class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Junit test: cannot find   test Method although that it is already defined in the test class" Watch "Junit test: cannot find   test Method although that it is already defined in the test class" New topic
Author

Junit test: cannot find test Method although that it is already defined in the test class

ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
Hello,

I have never used junit before and have a question regarding junit test:

I have the following method in my class SQLUtils:


I have created a unit test class in a new package for the method above:


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 can solve the problem please?

Thanks a lot in advance.


Ganesan Ponnusamy
EPractice Labs Support
Ranch Hand

Joined: Nov 07, 2005
Posts: 249
Please let me know the package name of Junit_TestSQL class.

Ganesan Ponnusamy Java Certification | Test Generator | OCAJP | OCPJP | OCEJWSD | EJB Certification
OCEJPAD | SCJD | SCWCD | SCBCD | SCDJWS | OCMJEA | Web Services Certification | SCMAD
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
Hello,

the package name is :



Thanks for your quick response.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

The name of the method should start with "test" with lower-case letters. So it should be: testLogIn instead of TestLogIn.

Note that you are using JUnit's old API, from before generics were introduced (Java 5). If you're using JUnit 4 or newer, you don't have to make your test class extend TestCase and you can name your test method whatever you like, as long as you put an @Test annotation above it:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
Thanks it is working fine and i will update my junit to a newer version. Thanks again ;)
ashley Jug
Ranch Hand

Joined: Sep 02, 2011
Posts: 60
Hello,

a quick question for the unit test, i am using maven to buld my project,

when i run the unit test manually from eclipse IDE it works fine but when i run the command mvn clean install it displays the following error msg:


However have the jar junit-3.8.1.jar in Referenced libraries and it contains the pakage junit.framework.

Any idea how i can resolve this issue?

Thanks again.
J J Singh
Greenhorn

Joined: Mar 20, 2010
Posts: 12
Have you added junit to maven dependency list ?

Something like

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.0</version>
<type>jar</type>
<scope>test</scope>
<optional>true</optional>
</dependency>


Please check it once
 
 
subject: Junit test: cannot find test Method although that it is already defined in the test class
 
Similar Threads
StrutsTestCase problem
Junit error
Easy Mock - Hibernate Session Factory issue?
NULL Pointer Exception
Exception when using setup() in a junit testcase