• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do i define Junit Testing without using @Test annotation?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a Junit Test file which has more number of methods. usually i perform testing for all the methods using @Test annotation. Now, i don't wish to give @Test annotation in all the methids without using annotation how to perform Junit Testing.

Please Note: I'm trying in Test Case not in Test suite.

I have attached my example below without @test annotation can anyone suggest me to write the junit test file without @Test annotation ?

public void Test() throws Exception {
try {
Long autoId = 8435L;
List<MySample> Test = MySampleDao.Test(autoId);
log.info("Test:"+ Test.size());
assertEquals(1, Test.size());
} catch (Exception e) {
log.error("Error in Test", e);
}
public void Sample() throws Exception {
try {
Long autoId = 8435L;
List<MySample> Sample = MySampleDao.Sample(autoId);
log.info("Sample:"+ Sample.size());
assertEquals(1, Sample.size());
} catch (Exception e) {
log.error("Error in Sample", e);
}
}
Note: If i run it shows no methods to test.

*Skip:*I'm trying this concept because i'm going for automation testing
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Note that in Java, there is a convention that methods begin with lower case.

I don't follow why you don't want to use the @Test that JUnit requires. You can do build automation while still using annotations.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Jeanne - you can do automation using annotations. No matter whether you use them or not, someone has to write the code. If you are writing the code (whether for automation or unit testing or functional testing or ...) you can add annotations.

This sounds more like an interview question, albeit not one I would want to ask. Something like - "how would you run a unit test in JUnit if annotations weren't available", or "how would you run a unit test in JUnit version 3". Both questions would feel very backward to me, but I could see them being asked if the company had a lot of legacy test cases, and wanted to find out if the candidate could work with them.

Pradeep - the standard for JUnit 3 was use a naming convention for tests. Test classes were named <something>Test.java, and the methods to be run were named test<Someting>. Something like:


By the way - see how I put my code between [code] and [/code] ubb code blocks? This makes it much easier to read the code. You might want to go back and edit your post to add the code tags to make your post more readable.
 
Pradeep dec
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Jeane. It could help me if you give me the suitable example to run the junit testing using automation tool by having @Test annotated in all the methods.
 
Pradeep dec
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andrew Monkhouse. My question is:

1. As you said Junit 3 follows naming convention if a class has more than ten methods then how to run all the methods at a stretch ?
2. Please refer this url they follows test case without @Test annotation - > https://github.com/junit-team/junit/blob/master/src/test/java/junit/tests/extensions/RepeatedTestTest.java

Note: Please don't mind if i'm wrong somewhere.

Thanks
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pradeep,
It would depend on which automation tool you are using. Ant provides a task to run JUnit tests. Maven runs JUnit tests. As does Sonar. All use the standard JUnit conventions.

The example you cited - RepeatedTestTest is a JUnit 3.8 test. It uses the naming convention where tests begin with "test". For example
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pradeep dec wrote:... if a class has more than ten methods then how to run all the methods at a stretch ?



JUnit is not limited by the number of test methods in a class, or the number of test classes. You could have 200 test methods in a single class, and JUnit will just run them all.
 
reply
    Bookmark Topic Watch Topic
  • New Topic