Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6998737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:26:58+00:00 2026-05-27T20:26:58+00:00

I have a project in Java with JUnit tests in Scala. Each test class

  • 0

I have a project in Java with JUnit tests in Scala. Each test class is annotated with @Test:

import org.junit.Test

@Test
class SomeTest {
  ...
}

JUnit API says that @Test is a method annotation. However, when I delete the @Test annotations from the classes while keeping method annotations intact, many tests are not executed when running from Eclipse.

So what is the purpose of @Test annotation applied to a class and why are some of the tests not run when these annotations removed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:26:58+00:00Added an answer on May 27, 2026 at 8:26 pm

    Scala does not check the ElementType for annotations (even outside of Scala IDE), so there is no ‘purpose’ for a @Test annotation for a class in Scala.

    In fact, you can apply any annotation to a class, Scala does not prevent this. Using the following example:

    import org.junit.Test
    import org.junit.Rule
    
    @Rule
    class Foo {
        @Test
        def test(filename: String) = println("test");
    }
    

    after compilation, you get a @Rule annotation on the class. This is a known feature, because AFAIK, you can ‘apply’ an annotation on a field in the source, but will actually end up on the method, if you use on of the target annotations.

    If you’re running your tests through any of the standard test runners, the @Test on the class shouldn’t make any difference. The only thing that counts is the @Test annotation on the method.

    When you’re using JUnit in Scala, you should follow the same rules as with Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my unit test cases for a Java project using Scala (JUnit
in my Java Eclipse project that contains JUnit tests, I also have a package
I have a Java project in Eclipse with ~10 packages and ~10 class files
Class under test MyClass.java JUnit test case name alternatives: TestMyClass.java MyClassTest.java http://moreunit.sourceforge.net seems to
I'm running some JUnit 4 tests in eclipse for my Java project which I
I'm using JUnit 4 (junit-4.8.2.jar) to run tests on my Java project and am
I have a test class, all the tests of this class runs fine if
I have Java project built with Maven2. There is used JUnit framework for testing
I have a project in Java. I want transform it to .NET-project. How to
I have a project in Java I am running that uses an external JAR

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.