Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

TestNG

Charla de TestNG (Comparativas con JUnit)
by

Jonathan Lopez

on 18 July 2013

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of TestNG

TestNG
Framework for testing
What is TestNG?
is an excellent alternative for JUnit
annotations,
listeners,
interceptors

TestNG JUnit 3
How difficult is migrate?
based on JUnit (Java) and NUnit (.NET)
pioneer using annotations (easiest in comparison than xml)
test methods support dynamic parameters
support for different
tools and plugins
can be invoke in different ways
Required as method name prefix "test"
Need extend of TestCase class
Impossibility setting parameters
Annotations, listeners, interceptors
is highly powerful, flexible and customizable
designed to cover all categories of tests unit, functional, end-to-end, integration, etc
Don´t required dependencies
also configurable by xml
testng.xml
@BeforeSuite
@AfterSuite
introduce new functionality dependency testing and grouping concept
@BeforeTest
@AfterTest
@BeforeClass
@AfterClass
@BeforeGroup
@AfterGroup
@Test
@BeforeMethod
@AfterMethod
No need to create (manually) own Threads
for parallel testing
Define test suite programatically
Only define suites by xml files
TestNG JUnit 4
JUnit parameterized input values must be in a different class.
JUnit have less annotations
(lack Before/After of Suite/Groups/Test )
Test'N'Groove
http://code.google.com/p/testngroove/
Documentation!
http://testng.org/doc/documentation-main.html
@DataProvider
@Listeners
@Parameters
@Test
@Before/@After
@Factory
How it flows?
@Annotations
Known Bugs!
alwaysRun
dataProvider
dependsOnGroups
dependsOnMethods
enabled
groups
timeOut
priority
expectedExceptions
alwaysRun
groups
enabled
dependsOn
name
parallel
values
Annotation
Transformer
public class MyFirstTestClass
{
@Test(priority="1")
public void test1() {
/* code */
}

@Test(timeout="1000", priority=2)
public void test2() {
/* code */
}

@Test(enable="false", expectedExceptions={IOException}, priority=2)
public void test3() {
/* code */
}
}
only public methods will be considerate as tests
lower number means high priority
@Test annotation could be specify
at class or method level
public final class TestingEnviroment {
@BeforeClass
public void setUpEnviroment() {
/* initialize */
}

@BeforeMethod
public void cleanEnviroment() {
/* clean data */
}

@AfterClass
public void tearDownEnviroment() {
/* stop and finalize */
}
}
@Test
{ Type.BPM,
"BPMProject1",
1 }
{ Type.BPM,
"BPMProject2",
3 }
@DataProvider
{ Type.BA,
"BAProject2",
2 }
@DataProvider(name="myProvider")
public Object[][] createData() {
return new Object[][] { { Type.BPM, "BPMProject", 1 },
{ Type.BA, "BAProject", 2 },
{ Type.BA, "BPMProject2", 3} }
}

@Test(dataProvider="myProvider")
public void methodTest(Type type, String name, int number) {
/* implement */
}
@Parameters
@Parameters( { "datasource", "jdbc" } )
public void testConnection(String source, String driver) {
/* connection data provide by params */
}

@Test
@Factory
TestingClass1
TestingClass2
TestingClass3
TestingClass4
public final class MyTestFactory {
@Factory
public Object[] TestFactory() {
List<Object> tests = new ArrayList<Object>();
for (int i = 1; i < 4; i++) {
tests.add(new TestClass(i));
}
return tests;
}
}
@Listeners
TestNG plugin for IntelliJ IDEA also provides a "Convert JUnit test to TestNG" feature.

Eclipse converter which does a decent job of changing imports, etc.
Even it´s pretty easy the migration,
there are some pluggins:
Some
features!

1) Change imports.
2) Remove unnecessary dependencies.
3) Done!
Follow the steps:
don't mess with class dependencies!
using factories? forget test sequentially
return value will be ignored unless set to true allow-return-values in your testng.xml
JUnit NOT support groups or test dependencies
JUnit
TestNG
@Test(group="full-regression")
public abstract MyDependentTestClass {
private data createData() {
return new Data();
}

@Test(groups="init")
public void initialize();

@Test(groups="GroupA", dependsOnGroup="init")
public void firstTestA();

@Test(groups="GroupA", dependsOnMethod="firstTestA")
public void secondTestA();

@Test(dependsOnGroup="GroupA")
public void firstTestB();

@Test(dependsOnGroup="GroupA")
public void secondTestB();
}
GroupA
init
Test Dependencies
IAnnotationTransformer
IHookable
IInvokedMethodListener
IMethodInterceptor
IReporter
ISuiteListener
http://testng.org/javadocs/org/testng/ITestNGListener.html
current version 6
created 2004
cedric@beust.com
Lack of test dependency and groups
Each test is independent
JDK 5.0
different class of
test defined
Test Classes
Test Groups
Test methods
@DataProvider
could be static!
Flexibility (DataProviders, Parameters, Exceptions expected, Test dependency)
BPM JUnit test modules:
Analitics
PML
Common-core
Composer
bpm-services
{String, String}
framework
primitive types
param1 = Type
param2 = String
param3 = int
"Listener for test suites"
"generates a report"
"modify a TestNG annotation"
"TestNG will run these methods in the
same order found in the returned value."
"A listener that gets invoked before
and after a method is invoked by TestNG"
"its run() method will be invoked instead of each @Test method found."
Lazy way!
Full transcript