Comments (9)
Georg,
I'd love to see something like this submitted to the junit.contrib project that I'm hoping to start up soon. Let me know if you're still interested, and thanks for your patience.
from junit4.
Georg,
I never heard back from you. Are you still interested in working on this? Thanks.
from junit4.
Just a question (for the sake of discussion): Would the proposed @SuiteMethod annotation in #41 work for you?
from junit4.
In principle, this works, but I would not consider this particularly convenient:
at least, a method needs to be implemented, which delegates to a static method somewhere (with the in-/exclude patters as arguments).
Furthermore, I find the syntax of my proposal much clearer.
I'd give, though, credit to you methods for more flexibility.
For me, the question angles around the answer to "how much flexibility is needed?".
IMHO - call me narrow minded if you wish ;-) - very little: the more complicated, the easier some tests "escape". The fine-tuning of tests, again - IMHO, should happen using the Assume-methods.
Do you have some software to test for which my proposal does not work?
from junit4.
For me it would not be enough. Sometimes I need to be able to group tests by name and location (that is the name is different depending on which directory). Why, because some tests are done as static inner classes to production code, while others are done in a separate test directory, and the separate test directory has a wider range of classes to include.
Sometimes I just want to slurp up all classes with an @test annotation in them.
from junit4.
Dear Yishai,
To "slurp up" all classes based on whether they have a @test annotation in them is not possible (to add some reflective inspection of the code wouldn't be too difficult, but very slow).
HOWEVER, I believe that inner classes are handled correctly, but I will run some examples first. Also, separate directories are no problem, as long as they are included in the class path.
I'll post examples asap...
Regards,
Georg
from junit4.
Dear Yishai,
here comes the promised example-cum-test for my modified Suite class. Both, the suites and the test-classes are inner classes. If you have the in the earlier post included Suite in your class path, you can run this class as a test or run the inner Suites individually.
Does this meet your needs?
Georg
package org.jlinalg.testutil.junit;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jlinalg.testutil.junit.Suite.SuiteClasses;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.JUnitCore;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
-
Tests for the execution of tests in inner classes.
-
@author Georg Thimm
/
@RunWith(Parameterized.class)
public class RunSuiteTest
{
/*- Tests add the class to which they belong here. This is used to assert
- that tese tests were executed.
*/
static List<Class> log = new ArrayList>();
/**
- 1st fixture: a suite based on a static class
_/
@RunWith(Suite.class)
@SuiteClasses(include = "._RunSuiteTestFixtureClass.*")
public static class StaticRunSuiteTestTest
{
}
/**
- 2st fixture: a suite based on a non-static class
_/
@RunWith(Suite.class)
@SuiteClasses(include = "._RunSuiteTestFixtureClass.*")
public class RunSuiteTestTest
{
}
/**
- Inner class with a test (used by both fixtures).
*/
public static class RunSuiteTestFixtureClass_1
{
@test
public void test()
{
log.add(getClass());
}
}
/**
- Inner class with a test (used by both fixtures).
*/
public static class RunSuiteTestFixtureClass_2
{
@test
public void test()
{
log.add(getClass());
}
}
/**
- @return A list arrays defining fixtures
*/
@parameters
public static List<Object[]> data()
{
Object[][] data_ = {
{
StaticRunSuiteTestTest.class
}, {
RunSuiteTestTest.class
}
};
return Arrays.asList(data_);
}
/**
- initialised fixture.
*/
private final Class<?> testSuiteClass;
/**
- Constructor
*/
public RunSuiteTest(Class<?> testSuiteClass)
{
this.testSuiteClass = testSuiteClass;
}
/**
- Test the execution of test suites.
- @throws ClassNotFoundException
*/
@test
public void testRunSuite() throws ClassNotFoundException
{
JUnitCore runner = new JUnitCore();
runner.run(testSuiteClass);
assertTrue("log=" + log, log.contains(RunSuiteTestFixtureClass_1.class));
assertTrue("log=" + log, log.contains(RunSuiteTestFixtureClass_2.class));
}
/**
from junit4.
georgthimm,
Thanks for the code. It may be slow to slurp up all the classes, but my point is that with a method that I can can control the programming of, I can do what I need (even if it is slow). With your solution, it is better than the current situation, it doesn't give the freedom to programatically take the classes from where I need them the way I need them. I have nothing against your suggestion, I'm just saying that it doesn't offer the same power as having a method that can return any array you can program.
from junit4.
Welcome! No offence taken, just me defending my stupid idea ;-)
I can see the advantages of your approach, and time isn't my main concern: robustness and easy to use are.
Cheers,
Georg
from junit4.
Related Issues (20)
- Confusing problem... get differernt result between `main method` and `test method` HOT 7
- Compilation error in org.junit.runner.Result - ObjectInputStream.GetField.get(name, object) throws ClassNotFoundException
- Update to hamcrest 2.2 HOT 16
- Test case grouping - Run subset of test cases depending on specific environment variables HOT 8
- Thread context classloader not reset between tests HOT 1
- Cross site scripting HOT 1
- How to test Redis Time out exception for @Cacheable method with Junit+ Spring integration test HOT 3
- Make Assert failNotEquals public HOT 1
- Assert error messages are not clear HOT 2
- Exception handling of suite() method breaks Jenkins JUnit test history reporting HOT 6
- Add support for "dynamic" default runner selection via system property HOT 8
- When will a new version of junit be released? HOT 1
- JUnitCore could not invoke test HOT 1
- Strange links on "Download and Install" page HOT 1
- junit-4.13.2 compilation error with java 21 HOT 4
- Treat org.opentest4j.TestAbortedException the same as AssumptionViolatedException HOT 4
- Which junit version supports Java 17 ? HOT 2
- Assert check not consistent HOT 9
- Receiving excessively long build DEBUG logs after updating maven-surefire-plugin from 2.22.2 to 3.3.0 HOT 1
- Refactoring Confirmation for Replace ‘expected’ Attribute with Try-Catch HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from junit4.