What’s the difference between ScalaTest and Scala Specs unit test frameworks?

Specs and ScalaTest are both good tools with happy users, but they differ in several ways. You will probably want to pick one as your main testing tool in Scala, but need not give up the other because you can use pieces of both. If you like ScalaTest’s FeatureSpec syntax and specs’ Mockito syntax, for … Read more

Unit Test? Integration Test? Regression Test? Acceptance Test?

Briefly: Unit testing – You unit test each individual piece of code. Think each file or class. Integration testing – When putting several units together that interact you need to conduct Integration testing to make sure that integrating these units together has not introduced any errors. Regression testing – after integrating (and maybe fixing) you … Read more

How to unit test a component that depends on parameters from ActivatedRoute?

The simplest way to do this is to just use the useValue attribute and provide an Observable of the value you want to mock. RxJS < 6 import { Observable } from ‘rxjs/Observable’; import ‘rxjs/add/observable/of’; … { provide: ActivatedRoute, useValue: { params: Observable.of({id: 123}) } } RxJS >= 6 import { of } from ‘rxjs’; … Read more

Any way to test EventEmitter in Angular2?

Your test could be: it(‘should emit on click’, () => { const fixture = TestBed.createComponent(MyComponent); // spy on event emitter const component = fixture.componentInstance; spyOn(component.myEventEmitter, ’emit’); // trigger the click const nativeElement = fixture.nativeElement; const button = nativeElement.querySelector(‘button’); button.dispatchEvent(new Event(‘click’)); fixture.detectChanges(); expect(component.myEventEmitter.emit).toHaveBeenCalledWith(‘hello’); }); when your component is: @Component({ … }) class MyComponent { @Output myEventEmitter … Read more

Test expected exceptions in Kotlin

The Kotlin translation of the Java example for JUnit 4.12 is: @Test(expected = ArithmeticException::class) fun omg() { val blackHole = 1 / 0 } However, JUnit 4.13 introduced two assertThrows methods for finer-granular exception scopes: @Test fun omg() { // … assertThrows(ArithmeticException::class.java) { val blackHole = 1 / 0 } // … } Both assertThrows … Read more