java


add codes to the afterclass in Junit


How can I add some codes to the #AfterClass method in unit test but without modifying the test source code and run it via junit cmd.
Here is my try but it does not override #AfterClass of the unit test.
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.Request;
import org.junit.AfterClass;
import org.junit.After;
import org.uni.DumpGenerator;
public class SingleJUnitTestRunner {
public static void main(String... args) throws ClassNotFoundException {
String classAndMethod = args[0];
Request request = Request.aClass(Class.forName(classAndMethod));
Result result = new JUnitCore().run(request);
}
#AfterClass
public static void afterClass() throws Exception, InterruptedException {
System.gc();
Thread.sleep(5000L);
DumpGenerator.dumpToFile("test", "afterRun");
}
}
and then I use this cmd:
java -cp pathtojunit SingleJUnitTestRunner Mytest
But the method afterclass does not work.
Any help!
Thanks in advance.
The #AfterClass annotation applies to a test case, not a test runner. You can either apply it to each test you want to run (or the base class, for that matter), or just call it directly in your main function:
public static void main(String... args) throws Exception, ClassNotFoundException {
String classAndMethod = args[0];
Request request = Request.aClass(Class.forName(classAndMethod));
Result result = new JUnitCore().run(request);
afterClass();
}

Related Links

Dialect class not found. \when using hibernate
hibernate reverse engineering column missing not null attribute
How should I efficiently extract stacktraces from a stream of log messages?
ArrayList and more primitive types togheter in Java
Opening Java enum method declarations in Eclipse
Java 2d game finding correct enemy for fighting
WELD-001318 Cannot resolve an ambiguous dependency between . . . in GlassFish 4
cannot use specification in findAll method in spring data jpa
Java Thrift AsyncIface / NonBlocking Server Questions
Not able to access session attributes in freemarker templates
Using Java on visual studio [duplicate]
How to get characters to a string in Java?
how the size of jpanel components in a specific layout can be set?
Why is my program not displaying the correct output? [duplicate]
Cleaning Tomcat server causes 500 error
Basic settings to be done for JFrog artifactory

Categories

HOME
google-chrome-extension
omnet++
kde
relayjs
cplex
leon
baqend
directx
add
volttron
numeral.js
visual-studio-2005
circuit
decomposition
workload-scheduler
systemc
transformation
riot.js
mps
mmap
hammerspoon
pepper
spark-jobserver
info.plist
atlassian-crucible
libuv
flink-streaming
binary-data
phonegap
airconsole
google-qpx-express-api
webtest
azure-sql-database
accelerate-framework
gammu
environment-modules
picasso
nssegmentedcontrol
neuroscience
occlusion
streamsets
code-search-engine
eclipse-scout
core-plot
password-encryption
arena-simulation
reactive-cocoa-5
azure-application-gateway
errordocument
logparser
blogengine.net
crypt
sqldf
home-directory
phishing
flash-cs5
qgraphicsview
nessus
ptrace
intel-fortran
fouc
varargs
map-projections
responsive-images
createprocessasuser
dereference
skos
formatjs
codeigniter-routing
android-2.2-froyo
balanced-payments
flexmojos
pyhdf
dataservice
back-stack
sqlperformance
flashvars
libstdc++
trusted
bluepill
manchester-syntax
propertyeditor
newtonscript
whoosh
data-loss
celltable
sql-server-profiler
subviews
h.323
sproutcore-2
ext3
mtj
w3wp
caching-application-block

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile